angularjs – 在嵌套的ng-repeat指令中使用ng模型
我正在尝试使用ng-model“内部”ng-repeat指令,它本身嵌套在ng-repeat指令中。
以下jsfiddle演示了我的问题和我的两个尝试来解决它。 http://jsfiddle.net/rskLy/4/ 我的控制器定义如下: 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控制台中显示两次错误:
有时它也会显示这个错误:
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中的矩阵)。 任何人都可以看清这个吗? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |