我从angularJS中的$http GET
获得了json样式的结果。
看起来像这样:
{
"meta":{
"limit":1000,
},
"objects":[
{
"custom_pk":"1",
"linked_client":null,
"resource_uri":"/api/v1/card_infos/1"
},
{
"custom_pk":"2",
"linked_client":null
}, ...
我想要一个包含所有
custom_pk
值的数组来做类似的事情:$scope.validate_pk = function(val){
if (val in myArray)
// do some stuff
您如何创建myArray?
最佳答案
您可以像这样提取对象:
var json = ... the javascript object shown in your question
var custom_pks = [];
for (var i = 0; i < json.objects.length; i++) {
custom_pks.push(json.objects[i].custom_pk);
}
// at this stage the custom_pks array will contain the list of all
// custom_pk properties from the objects property
关于javascript - 解析$ http结果以获取AngularJS中的特定项目,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22579728/