Angularjs 如何循环数组中的数组?
假设我有这样的json字符串:Angularjs 如何循环数组中的数组?,angularjs,Angularjs,假设我有这样的json字符串: { "subData" : [ ["a", "b", "c" , "d"] ] } 我无法使用以下方法循环遍历阵列中的数据: <tbody> <tr ng-repeat="temp in subData"> <td ng-repeat="value in temp"> {{value}} </td> </tr> </tbody>
{ "subData" : [ ["a", "b", "c" , "d"] ] }
我无法使用以下方法循环遍历阵列中的数据:
<tbody>
<tr ng-repeat="temp in subData">
<td ng-repeat="value in temp">
{{value}}
</td>
</tr>
</tbody>
我错过什么了吗
谢谢是的,您错过了餐桌标签
对我来说很有用,你有没有一个实际的表元素包装这个tbody
<table>
<tbody>
<tr ng-repeat="temp in subData">
<td ng-repeat="value in temp">{{value}}</td>
</tr>
</tbody>
</table>
您是否正确地将数据放入$scope中
另外,我建议您在删除阵列时使用track by$index,以避免数据重复问题
JS:
HTML:
你说的json字符串…发布包含subDataHi的完整对象,谢谢你的回复。json对象非常简单。我更新了json示例。确保数据被正确分配给作用域,即如果$scope.data是$scope.data={subData:[[a,b,c,d]};您需要在数据中重复ng=temp。subData@imguru建议您将OP对象粘贴到jsonlint.com中,并会发现它是valid@imguru:你的意思是我需要一个密钥对值才能使用ng repeat?这有什么不同?tag是missedIt假设表标记在那里可能相当安全-问题似乎是子数据不是$scope变量名。奇怪的是…如果我的数组有重复值,ng repeat不会呈现{subData:[[a,a,c,d]}请按$index添加track by$ie:value in temp track by$index
<table>
<tbody>
<tr ng-repeat="temp in subData">
<td ng-repeat="value in temp">{{value}}</td>
</tr>
</tbody>
</table>
angular.module('app', [])
.controller('appCtrl', function($scope) {
$scope.subData = [ ["a", "b", "c" , "a"], ["a", "a", "c" , "c"] ];
});
<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>