0

obj.attributes が次のリストにあるこの json 応答があります。ID を持つ各オブジェクトのみを通過したい..オブジェクトをトラバースして id 属性を出力するにはどうすればよいですか

Object {0: Object, 1: Object, 2: Object, 3: Object, subject_Keys: "", schoolapplication: Object}

私は試した

for(var item in obj.attributes)
{
     var intRegex = /^\d+$/;
 if(intRegex.test(item)) {
       console.log(obj.attributes[item]["id"]) //This prints undefined
     }
}

EDIT1:console.log(obj)

child {cid: "c33", changed: Object, attributes: Object, _changes: Array[0], _hasComputed: true…}
_changes: Array[0]
_changing: false
_currentAttributes: Object
_hasComputed: true
_pending: false
_previousAttributes: Object
app_id: 8
attributes: Object
changed: Object
cid: "c33"
__proto__: Surrogate

console.log(obj.attributes)

 Object {0: Object, 1: Object, 2: Object, 3: Object, subject_Keys: "", schoolapplication: Object}  
 0: Object
   name: "key1"
   schoolapplication: Object
   id: 3
   __proto__: Object
1: Object
2: Object
3: Object
__proto__: Object
4

1 に答える 1

1

オブジェクト全体にデータを与えると、役に立ちます。しかし、私が理解していることは、この解決策を得ました

for(var item in obj)
{
    if(obj[item].hasOwnProperty('id')) {
        console.log(obj[item].id);
    }
}
于 2013-09-30T09:34:32.587 に答える