Geo*_*ang 7 angularjs ng-repeat
我有一个包含对象列表的数组.每个对象还包括一个数组(见下文).我正在使用ng-repeat来遍历每个对象的子数组,我尝试了许多不同的方法,但它根本不起作用.任何提示,方向,帮助将非常感激.谢谢.:-)
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.js"></script>
<script>
angular.module('mlApp', [])
.controller('mlCtrl', [function () {
var self = this;
self.contacts = [
{ contact: 'AAA', mlist: [1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1] },
{ contact: 'BBB', mlist: [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1,1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1] }
];
} ]);
<div ng-app="mlApp" ng-controller="mlCtrl as mCtrl">
<table>
<thead>..</thead>
<tbody>
<tr ng-repeat="p in mCtrl.contacts">
<th width="100px" >{{p.contact}}</th>
<td ng-repeat="c1 in p.mlist"><input type="checkbox" ng-check='{{c1}}' /></td>
</tr>
</tbody>
</table>
</div>
Run Code Online (Sandbox Code Playgroud)
Sho*_*omz 12
提示是检查控制台是否有错误 - Angular(通常)对这些事情非常有帮助.
您在内部ng-repeat中使用的数组中有重复值,因此需要通过某些内容进行跟踪.我在这个例子中使用了$ index:
angular.module('mlApp', [])
.controller('mlCtrl', [
function() {
var self = this;
self.contacts = [{
contact: 'AAA',
mlist: [1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1]
}, {
contact: 'BBB',
mlist: [0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1]
}
];
}
]);Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="mlApp" ng-controller="mlCtrl as mCtrl">
<table>
<thead>..</thead>
<tbody>
<tr ng-repeat="p in mCtrl.contacts">
<th width="100px">{{p.contact}}</th>
<td ng-repeat="c1 in p.mlist track by $index">
<input type="checkbox" ng-check='{{c1}}' />
</td>
</tr>
</tbody>
</table>
</div>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
25487 次 |
| 最近记录: |