gpt4 book ai didi

javascript - 使用 ng Repeat 显示 JSON

转载 作者:行者123 更新时间:2023-12-02 16:48:29 26 4
gpt4 key购买 nike

我有一个格式为 JSON 的数据

[

{
"_1": {
"id": 4,
"cost": 45.0,
"measure": 4,
"NoOfUnits": 677,
"hours": null
},
"_2": {
"id": 1,
"name": "Truck",
"description": "Test"
}
},
{
"_1": {
"id": 1,
"cost": 1120.0,
"measure": 1,
"NoOfUnits": 500,
"hours": null
},
"_2": {
"id": 7,
"name": "PC300",
"description": null
}
},
]

我无法显示存储在 $scope 变量中的数据

$scope.result

这是我的 ng 重复功能

<div ng-repeat="data in result">{{data.name}}{{data.description}}</div>

最佳答案

您的$scope.result包含2个对象,其中一个对象中您有一组对象属性,例如_1, _2 ,然后这些属性又是像

这样的对象
"_1": {
"id": 4,
"cost": 45.0,
"measure": 4,
"NoOfUnits": 677,
"hours": null
}

,那么您就有了需要打印的属性

<ul>
<li ng-repeat="x in result"> // repeats objects
<ul ng-repeat="obj in x"> // repeat object properties '_1',"_2" , these are again objects
{{obj.name}}{{obj.description}}
<ul>
</li>
</ul>

关于javascript - 使用 ng Repeat 显示 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26901910/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com