繁体   English   中英

数组内对象的角度复选框

[英]Angular checkboxes for objects within array

我有一个包含对象的数组。 每个对象都有一个布尔变量(array [i] .check)。 我想使用AngluarJS创建一个表,通过单击一个复选框直接更改数组中特定对象的布尔值。我使用:

 <table> 
    <tr  data-ng-repeat="a in array">
            <td style="width:200px;"> {{a.name}}</td>   
            <td><input type="checkbox"  ng-model="a.check"  ng-checked="a.check"></td>
    </tr>
 </table>

但是,每个布尔值始终为假。 我做错了什么?

您能尝试单独使用ng-model这种方法吗,我用工作方法创建了一个小提琴,应用了此代码,然后与问题分享回来,我将为您解决!

 var app = angular.module('myApp', []); app.controller('MyController', function MyController($scope) { $scope.array = [{id:1, name: "test1", changeThisValue: false},{id:2, name: "test2", changeThisValue: true},{id:3, name: "test3", changeThisValue: true},{id:4, name: "test4", changeThisValue: true},{id:5, name: "test5", changeThisValue: true}]; }); 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> <div ng-controller='MyController' ng-app="myApp"> <table> <tr data-ng-repeat="a in array"> <td style="width:200px;"> {{a.name}}</td> <td> <input type="checkbox" ng-model="a.changeThisValue"> </td> </tr> </table> <pre style="width:100px;white-space: pre-wrap;">{{array}}</pre> </div> 

暂无
暂无

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

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