假设我有这样的json字符串:
{ "subData" : [ ["a", "b", "c" , "d"] ] }
我无法使用以下方法遍历数组中的数据:
<tbody>
<tr ng-repeat="temp in subData">
<td ng-repeat="value in temp">
{{value}}
</td>
</tr>
</tbody>
我错过了什么吗?
由于
答案 0 :(得分:1)
您是否正确地将数据放入$scope
?
另外,我建议你在删除数组时使用track by $index
,以避免数据重复问题
JS:
angular.module('app', [])
.controller('appCtrl', function($scope) {
$scope.subData = [ ["a", "b", "c" , "a"], ["a", "a", "c" , "c"] ];
});
HTML:
<table ng-app="app" ng-controller="appCtrl">
<tbody>
<tr ng-repeat="temp in subData">
<td ng-repeat="value in temp track by $index">
{{value}}
</td>
</tr>
</tbody>
</table>
答案 1 :(得分:0)
适合我,你有一个实际的表元素包装那个tbody吗?
<table>
<tbody>
<tr ng-repeat="temp in subData">
<td ng-repeat="value in temp">{{value}}</td>
</tr>
</tbody>
</table>
答案 2 :(得分:-1)
是的,你错过了表格标签 http://jsbin.com/wozido/1/edit
<table>
<tbody>
<tr ng-repeat="temp in subData track by $index">
<td ng-repeat="i in temp track by $index">
{{i}}
</td>
</tr>
</tbody>