[英]AngularJS checkbox selected in a list
I have a list called positions
that has N positions in them. 我有一个名为
positions
的清单,其中有N个职位。 I also have a user user
that has an attribute user.positions
that has some of the positions assigned to. 我也有一个用户
user
,该用户具有一个属性user.positions
,该属性已分配了一些位置。
I want to show a form with all the possible positions, and the positions that the user already has to be checked. 我想显示一个表格,其中包含所有可能的位置,以及必须检查用户的位置。
Is this something I can do inside the HTML, or do I need to loop through both in my logic and create a new variable? 这是我可以在HTML内部执行的操作,还是需要在我的逻辑中循环遍历并创建一个新变量?
<label ng-repeat="position in positions">
<input type="checkbox" ng-checked="user.positions.indexOf(position) != -1" /> {{position}}
</label>
http://jsfiddle.net/t4ZQd/ http://jsfiddle.net/t4ZQd/
https://docs.angularjs.org/api/ng/directive/ngRepeat https://docs.angularjs.org/api/ng/directive/ng重复
https://docs.angularjs.org/api/ng/directive/ngChecked https://docs.angularjs.org/api/ng/directive/ng已检查
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.