如何使用Angular.js从json文件中使用id获取特定数据
16lz
2021-01-22
i need one help.I need to fetch data from my data.json file using the unique id.I am explaining my code below.
我需要一个帮助。我需要使用唯一的id从我的data.json文件中获取数据。我正在解释下面的代码。
$scope.editProfileData=function(){
var editid={'id':2};
$http({
method: 'POST',
url: 'profile.json',
data:editid
}).then(function successCallback(response){
},function errorCallback(response) {
});
}
Here i need when the condition (id==2
) will match in json file it will fetch those specific data.Please help me.
这里我需要当条件(id == 2)在json文件中匹配时它将获取那些特定数据。请帮助我。
2 个解决方案
#1
2
Try it:
尝试一下:
//...
}).then(function successCallback(response){
var i, l = response.data.length;
for(i = 0; i < l; i++){
if( response.data[i].id == 2){
fetch( response.data[i]); // your fetch code here
break;
}
}
}).
//...
更多相关文章
- javaScript怎么实现双向数据绑定
- 如何从一个节点生成exe文件。js应用?
- 使用Directive通过AngularJS使用指令和数据绑定来注入HTML
- 一旦db通过Node.js发生更新,就立即推送数据
- ng- repeat显示的行等于no属性,甚至不显示html视图上的数据
- 将数据从AJAX请求序列化到PHP
- 在Servlet和HTML页面之间处理函数调用和数据传输的最佳方法是什
- 使用HTML文件中的React调用.js文件中的Javascript函数
- 访问D3的var格式数据