I'm trying to show the values of a specific JSON in the right Order. My JSON looks like :
我正在尝试以正确的顺序显示特定JSON的值。我的JSON看起来像:
{
"A":[{"id":"21","name":"Andrea"},{"id":"22","name":"Apple"}],
"B":[{"id":"21","name":"Baby"},{"id":"22","name":"Bali"}],
"C":[{"id":"21","name":"Candle"},{"id":"22","name":"Canada"}],
}
How to show values with ng-repeat :
如何使用ng-repeat显示值:
<div ng-repeat="item in items">
</div>
like :
喜欢 :
A
一个
Andrea
安德里亚
Apple
苹果
B
乙
Baby
宝宝
Bali
巴厘岛
C
C
Candle
蜡烛
Canada
加拿大
4 个解决方案
#1
4
Please check working example: http://plnkr.co/edit/lqoQvmXnimWYzqVU0wkg?p=preview
请查看工作示例:http://plnkr.co/edit/lqoQvmXnimWYzqVU0wkg?p = preview
HTML
HTML
<div ng-repeat="(key, values) in items">
{{key}}
<div ng-repeat="item in values">
{{item.name}}
</div>
</div>
#2
1
you can iterate over the object with:
您可以使用以下内容迭代对象:
<div ng-repeat="(key, value) in jsonData">
{{key}}
<div ng-repeat="item in value">
<div>{{item.name}}</div>
</div>
</div>
edit: I see the other guys added jsfiddle so enjoy :)
编辑:我看到其他人添加jsfiddle所以享受:)
#3
1
If your data be like this :
如果您的数据是这样的:
$scope.items={
"A":[{"id":"21","name":"Andrea"},{"id":"22","name":"Apple"}],
"B":[{"id":"21","name":"Baby"},{"id":"22","name":"Bali"}],
"C":[{"id":"21","name":"Candle"},{"id":"22","name":"Canada"}],
}
Consider item as map and iterate for (key,value) in map and the value will be associated List. And again iterate for the list in values as -
将item视为map并在map中迭代(key,value),该值将与List相关联。并再次迭代值中的列表 -
<div ng-repeat="(key,value) in items">
{{key}}
<div ng-repeat="item in value">
{{item.name}}
</div>
</div>
#4
0
Try this plunker.
试试这个plunker。
You print key
of your json too so you should use '(key,value)' in ng-repeat to get value of key too.
你也打印你的json的键,所以你应该在ng-repeat中使用'(key,value)'来获得key的值。
code:
码:
<div ng-repeat="(key,value) in data">
{{key}}
<div ng-repeat="item in value">
{{item}}
</div>
</div>
#1
4
Please check working example: http://plnkr.co/edit/lqoQvmXnimWYzqVU0wkg?p=preview
请查看工作示例:http://plnkr.co/edit/lqoQvmXnimWYzqVU0wkg?p = preview
HTML
HTML
<div ng-repeat="(key, values) in items">
{{key}}
<div ng-repeat="item in values">
{{item.name}}
</div>
</div>
#2
1
you can iterate over the object with:
您可以使用以下内容迭代对象:
<div ng-repeat="(key, value) in jsonData">
{{key}}
<div ng-repeat="item in value">
<div>{{item.name}}</div>
</div>
</div>
edit: I see the other guys added jsfiddle so enjoy :)
编辑:我看到其他人添加jsfiddle所以享受:)
#3
1
If your data be like this :
如果您的数据是这样的:
$scope.items={
"A":[{"id":"21","name":"Andrea"},{"id":"22","name":"Apple"}],
"B":[{"id":"21","name":"Baby"},{"id":"22","name":"Bali"}],
"C":[{"id":"21","name":"Candle"},{"id":"22","name":"Canada"}],
}
Consider item as map and iterate for (key,value) in map and the value will be associated List. And again iterate for the list in values as -
将item视为map并在map中迭代(key,value),该值将与List相关联。并再次迭代值中的列表 -
<div ng-repeat="(key,value) in items">
{{key}}
<div ng-repeat="item in value">
{{item.name}}
</div>
</div>
#4
0
Try this plunker.
试试这个plunker。
You print key
of your json too so you should use '(key,value)' in ng-repeat to get value of key too.
你也打印你的json的键,所以你应该在ng-repeat中使用'(key,value)'来获得key的值。
code:
码:
<div ng-repeat="(key,value) in data">
{{key}}
<div ng-repeat="item in value">
{{item}}
</div>
</div>