下面是名爲data的嵌套對象。在這裏我想顯示所有的對象鍵和值。對於我已經寫了代碼,低於:如何訪問另一個對象內的對象?
var data = {
response: {
deals: [
{
id: 1,
color: {
id: 608290
}
}
]
}
};
使用下面的代碼我已經達到訪問對象交易的「ID」這是關鍵,它的值是1,但給人的翻譯:顏色,因爲它有它自己的鍵和值,例如id:608290。我也想展示它。請對代碼進行一些更改,以獲取交易中顏色對象的該鍵和值。
for(var i = 0; i <= data.response.deals.length-1;i++){
$.each(meta.response.deals[i], function(key, value) {
alert(key + ": " + value);
});
'meta.response.deals'是一個數組嗎? –
是:'deals:[{id:1,color:{id:608290}}]'。它是一組對象。 – Broxzier
你的問題很混亂。你的對象圖是'metal.deals'還是'meta.response.deals'? –