2013-01-24 54 views
1

我想遍歷這個節點,我從AJAX調用中獲得回來,並且遇到問題。我試圖訪問位於facet/#/@attributes/namename節點。我目前處於#的等級,但對如何進入@ attributes的等級感到困惑。遍歷jQuery中的這個節點

console.log(data.categories); //outputs what you see below. 
$(data.categories.facet).each(function(key, value) { 
    console.log(key + ' : ' + value.attributes); //outputs undefined 
}); 

enter image description here

+0

'的console.log(鍵+ '​​:' +值[ '@屬性']名稱);' – Musa

+0

@Musa我不斷收到錯誤'未捕獲的SyntaxError:意外的令牌)' – Jon

+0

對不起錯字'控制檯.log(key +':'+ value ['@ attributes']。name);' – Musa

回答

2

必須使用方括號標記[]才能訪問包含特殊字符的對象的屬性,例如@attributes中的@

console.log(key + ' : ' + value['@attributes'].name); 
0

我不習慣我認爲是鍍鉻的控制檯。

但方面[0] .name不返回「評級」?