动态节点生成功能

Dynamically node generation function

本文关键字:功能 成功 节点 动态      更新时间:2023-09-26
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]等(。哈希图是可能的吗?

你需要在

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
});