我正在尝试使用ng-model“内部”ng-repeat指令,它本身嵌套在ng-repeat指令中。
我的控制器定义如下:
var mod = angular.module('TestApp',[]); mod.controller('TestCtrl',function ($scope) { var machine = {}; machine.noteMatrix = [ [false,false,false],[false,true,false] ]; $scope.machine = machine; // ... });
1。
<table> <thead> <tr> <th>--</th> <th ng-repeat="no in machine.noteMatrix[0]">{{$index+1}}</th> </tr> </thead> <tbody> <tr ng-repeat="track in machine.noteMatrix"> <td>--</td> <td ng-repeat="step in track"> <input type="checkBox" ng-model="track[$index]"> {{step}} </td> </tr> </tbody> </table>
第一个示例/尝试更新控制器内的machine.noteMatrix,但是每当按下复选框时,angularjs会在javascript控制台中显示两次错误:
Duplicates in a repeater are not allowed. Repeater: step in track
Duplicates in a repeater are not allowed. Repeater: no in machine.noteMatrix[0]
2。
<table> <thead> <tr> <th>--</th> <th ng-repeat="no in machine.noteMatrix[0]">{{$index+1}}</th> </tr> </thead> <tbody> <tr ng-repeat="track in machine.noteMatrix"> <td>--</td> <td ng-repeat="step in track"> <input type="checkBox" ng-model="step"> {{step}} </td> </tr> </tbody> </table>
第二个示例/尝试从notesMatrix读取数据,并且在检查/取消选中复选框时,javascript控制台中不会显示任何错误。但是,更改其状态并不会更新控制器中的machine.noteMatrix(按“显示矩阵”按钮可查看jsfiddle中的矩阵)。
任何人都可以看清这个吗?
原文地址:https://www.jb51.cc/angularjs/144169.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。