var v = [
{
"message": {
"code": "S200",
"message": "Success"
},
"data": {
"car": [
{
"id": 1,
"val": "Toyota"
},
{
"id": 2,
"val": "Honda"
},
{
"id": 3,
"val": "Nissan"
}
],
"truck": [
{
"id": 1,
"val": "Benz"
},
{
"id": 1,
"val": "Volvo"
}
]
}
}
]
我有一个如上所示的动态 json。
如何在 undescorejs 或 angularjs 中动态获取 v[0].data.car 节点(不使用 v[0]、v[1] 等)。 Hashmap可以吗?
最佳答案
您需要在 angularjs 中迭代数组,如下所示
v.forEach(function(element){
console.log(element.data.car[0]);//Over here you can again iterate the car array, I have used the first element instead
});
关于javascript - 动态节点生成功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25932393/