【发布时间】:2015-06-02 07:20:14
【问题描述】:
我有如下的json,
{
"natureitems": [
{
"groups": "fruits",
"items": [
{
"name": "apple",
"properties": {
"color": "red",
"shape": "round"
}
},
{
"name": "orange",
"properties": {
"color": "orange",
"shape": "round"
}
}
]
},
{
"groups": "vegitables",
"items": [
{
"name": "carrot",
"properties": {
"color": "red",
"shape": "cone"
}
},
{
"name": "tomoto",
"properties": {
"color": "red",
"shape": "round"
}
}
]
}
]
}
我需要一个像 li ng-repeat(角度视图)这样的输出
------------------
fruits(these titles row in different background colors)
------------------
apple - round
orange - round
----------------
vegitables
---------------
carrot - cone
tomoto - round
我尝试了很多 for 循环和 angular foreach,但我分别获取项目和组。但是在那之后试图把上面的结构(title-items-title-items)引入一个数组就很难了。
是否有任何简单的方法可以将这些格式的项目放入数组或对象中?这样我就可以轻松绑定到 ng-repeat!
【问题讨论】:
-
为什么要单级列表?
-
好的.. 不需要是单级列表。输出需要格式足够好。
标签: javascript json angularjs