假设我们有以下JSON文件:
{
"MainRegister": {
"description": "Hello World",
"identifier": "01",
"specifications": [
{
"usage": "Retail",
"other": {
"type": "Finance",
"included": "True"
}
]
}
}
在进行ng-repeat时,我现在如何访问包含中最深的字段?我尝试了以下方法:
<div ng-repeat="entry in entries">
{{entry.description}}
<span ng-repeat="specs in entry.specifications">
{{specs.usage}}
<span ng-repeat="subspecs in specs.other">
{{subspecs.included}}
<span/>
<span/>
</div>
执行此操作时,{{entry.description}}和{{specs.usage}}将起作用并显示“Hello World”和“Retail”。但是,{{subspecs.included}}不起作用....而且,当嵌套两次以上时,我们就会遇到问题。这是什么解决方案?谢谢
答案 0 :(得分:3)
Other
是object
,而不是collection
...
"other": {
"type": "Finance",
"included": "True"
}
那么,你可以输出specs.other.included
吗?
<div ng-repeat="entry in entries">
{{entry.description}}
<span ng-repeat="specs in entry.specifications">
{{specs.usage}}
<br />
{{subspecs.other.included}}
<span/>
</div>
编辑:基于评论
将other
作为集合是否有意义?你会有吗?
"other": [{
"type": "Finance",
"included": "True"
},
{
"type": "Sport",
"included": "False"
}
]
如果没有,请保持原样,然后删除最后一个ng-repeat
。