我从$http GET
angularJS中获得了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
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句