[英]Traverse simple javascript object
I'm having a mental block. 我有精神障碍。 How may I access the data inside this javascript object that's returned from an ajax function?
我如何访问从ajax函数返回的此javascript对象内的数据?
I was thinking something like this would work: 我在想这样的事情会起作用:
data[0].id would return 1
data[1].category.description would return "MEN"
Help would be appreciated! 帮助将不胜感激!
"[ {
"id" : 1,
"description" : "PANTS",
"price" : 10.99,
"category" : {
"id" : 1,
"description" : "MEN"
},
"customerType" : {
"id" : 1,
"type" : "COUNTER"
}
}, {
"id" : 2,
"description" : "SHIRT",
"price" : 4.99,
"category" : {
"id" : 1,
"description" : "MEN"
},
"customerType" : {
"id" : 1,
"type" : "COUNTER"
}
} ]"
That should work, just loop over it 那应该工作,只是遍历它
dataLength=data.length;
for(var i=0;i<dataLength;i++){
var dataID = data[i].id;
var dataCatagory = data[i].category.description;
}
ah jeez.. I figured out a simple way to get the data out. 啊,我..我想出了一种简单的方法来获取数据。 I can do something like this:
我可以做这样的事情:
currentrow = data[i];
id = currentrow.id;
Or use id or the other values as such. 或者使用id或其他值。 Nevermind my posting, I'm an idiot sometimes
没关系,我有时候是个白痴
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.