[英]displaying nested json in ng-repeat
I seem to be having difficulty in grasping how to drill down to get to nested JSON and display it on a page using angular. 我似乎很难掌握如何深入了解嵌套的JSON并使用angular将其显示在页面上。 For example I have the following JSON structure and I want to display the connectivity products under portfolio in an ng-repeat...
例如,我具有以下JSON结构,并且我想以ng-repeat显示投资组合下的连接产品...
{
"addons": [
...
],
"attributes": [
...
],
"portfolios": [
{
"connectivity": [
{
"product-1": {
"label": "product-1",
"description": "Description in here"
}
},
{
"product-2": {
"label": "product-2",
"description": "Description in here"
}
}
]
}
]
} }
So far I have tried it two different ways. 到目前为止,我已经尝试了两种不同的方法。
$scope.listOfProducts = allProducts.data.portfolios.connectivity;
and in the ng-repeat 并在ng-repeat中
ng-repeat='product in listOfProducts.portfolios.connectivity'
What would be the correct way to loop through and display the 'connectivity' products in a ng-repeat? 在ng-repeat中循环显示“连接性”产品的正确方法是什么? Thanks
谢谢
EDIT: 编辑:
I've changed the JSON to this structure... 我已经将JSON更改为此结构...
{
"addons": [
...
],
"attributes": [
...
],
"portfolios": [
{
"connectivity": [
{
"label": "product-1",
"description": "Description in here"
},
{
"label": "product-2",
"description": "Description in here"
}
]
}
]
But I still can't seem to get ng-repeat to display the products in connectivity. 但是我似乎仍然无法通过ng-repeat来显示连接中的产品。
$scope.listOfProducts = allProducts.data.portfolios.connectivity $ scope.listOfProducts = allProducts.data.portfolios.connectivity
Since listOfProducts
is already set to the connectivity
array, you would just ng-repeat="product in listOfProducts"
由于
listOfProducts
已设置为connectivity
数组,因此您只需ng-repeat="product in listOfProducts"
<div ng-repeat="product in listOfProducts">
{{product.label}}
</div>
Edit: Well, your array is sort of irregular, since you're creating a property called product-[index]
for each item. 编辑:嗯,您的数组有点不规则,因为您正在为每个项目创建一个名为
product-[index]
的属性。 Do you have control of the data which is returned? 您控制返回的数据吗? Your array should just have the objects, like:
您的数组应该只包含对象,例如:
"connectivity": [
{
"label": "product-1",
"description": "Description in here"
},
{
"label": "product-2",
"description": "Description in here"
}
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.