繁体   English   中英

使用数组遍历对象属性

[英]Iterating over object properties with arrays

这是我的数据结构:

$scope.table = {
                    a: ["1","2","3","4"],
                    b: ["5","6","7","8"]
               };

我可以使用ng-repeat遍历各个键:

<tr ng-repeat="(key,value) in table">
    <td>{{key}}</td> <!-- display a, b-->
    <td ng-repeat="???"></td>
</tr> 

我还想在键后遍历values数组,我应该如何继续?

谢谢!

如果要遍历属性内部的数组,可以执行以下操作:

 angular.module('app', []) .controller('mainCtrl', function($scope) { $scope.table = { a: ["1","2","3","4"], b: ["5","6","7","8"] }; }); 
 <!DOCTYPE html> <html ng-app="app"> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.7/angular.min.js"></script> </head> <body ng-controller="mainCtrl"> <table> <tr ng-repeat="(key, values) in table"> <td ng-bind="key"></td> <td ng-repeat="value in values" ng-bind="value"></td> </tr> </table> </body> </html> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM