我创建了一些模拟数据,我将在我的角度应用程序项目中使用以下结构:
var videos = [
{
category:
[
{ explainer:
[
'explain1',
'explain2',
'explain3',
]
},
{ cartoon:
[
'cartoon1',
'cartoon2',
'cartoon3',
]
},
{ moGraph:
[
'moGraph1',
'moGraph2',
'moGraph3',
]
},
]
}
];
好的,我想对数据做些什么:
我尝试使用<ng-repeat="video in videos track by $index">
,但我只设法让它适用于像(var projects = [ 'proj1', 'proj2', 'proj3'];
)
我真的对如何做到这一点感到困惑,请多多指教谢谢
答案 0 :(得分:1)
看起来你只需要有很多嵌套的中继器。例如......
<div ng-repeat="video in videos">
<div ng-repeat="categories in video.category">
<div ng-repeat="category in categories">
<div ng-repeat="(catName, datas) in category">
<h3>{{ ::catName }}</h3>
<ul>
<li ng-repeat="data in datas">{{ ::data }}</li>
</ul>
</div>
</div>
</div>
</div>
就个人而言,我会将数据格式更改为更像......
var videos = [
{
explainer: ['explain1', 'explain2', 'explain3'],
cartoon: ['cartoon1', 'cartoon2', 'cartoon3']
moGraph: ['moGraph1', 'moGraph2', 'moGraph3']
}
];
然后你需要的只是......
<div ng-repeat="video in videos">
<div ng-repeat="(category, datas) in video">
<h3>{{ ::category }}</h3>
<ul>
<li ng-repeat="data in datas">{{ ::data }}</li>
</ul>
</div>
</div>