在我的 Controller 中,我有这样的数据......
data = {
chartTypes":["pie","donut","bar","line"],
"features":{
"stacked": ["true","true","true","false"],
"percentage":["false","false","true","false"]
}
};
$scope.docStructure = data
有什么方法可以让我使用 ng-repeat 遍历键并在值是数组时再次迭代?
<div ng-app="chartFeatures" ng-controller="chartFeaturesCtrl" style="height:200px; background:red;">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<th> </th>
<th ng-repeat="chartType in docStructure.chartTypes">{{chartType}}</th>
</tr>
<tr ng-repeat="(feature,supportedList) in docStructure.features">
<td>{{feature}}</td>
<td ng-repeat="supported in supportedList">{{supported}}</td>
</tr>
</table>
</div>
我的想法是我想做一个交叉表,如下所示。
例子:
最佳答案
你只需要在 td 标签的 ng-repeat 中添加 track by $index
<td ng-repeat="supported in supportedList track by $index">{{supported}}</td>
这是一个 demo
您还可以将“特征”数组转换为包含对象而不是基元,这样您就不需要track by $index
这是一个 demo
关于javascript - 当动态键值为数组时,如何使用 ng-repeat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23818411/