作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个场景,当在 ng-repeat 中选中复选框时,我必须将值放入数组中。
<li ng-repeat="player in team.players">
<div class="row">
<div class="col-md-3 m-t-xs">
<input type="checkbox" ng-model="vm.newEvent.players[$index].selected" ng-change="vm.selectPlayer($index, player)"> {{player.name}}
</div>
<div class="col-md-5 m-t-xs">
<label for="">
<input type="radio" name="{{player.id}}" ng-change="vm.disSelectPlayer($index, player)" ng-model="vm.newEvent.players[$index].casuality.type" value="injured"> Injured
</label>
<label for="">
<input type="radio" name="{{player.id}}" ng-change="vm.disSelectPlayer($index, player)" ng-model="vm.newEvent.players[$index].casuality.type" value="sick"> Sick
</label>
<label for="">
<input type="radio" name="{{player.id}}" ng-change="vm.disSelectPlayer($index, player)" ng-model="vm.newEvent.players[$index].casuality.type" value="other"> Other
</label>
</div>
</div>
</li>
这是它现在在浏览器中的样子。
问题是,当我点击 FC Barcelona Accordion 中的任何球员姓名时,它也会从 FC Bayern Munich Accordion 中选择相同的索引球员,我想要的是让所有玩家彼此分开。我在绑定(bind)中遗漏了什么吗??
最佳答案
为复选框列表使用 list 模型、AngularJS 指令
在 Angular 中一个复选框 <input type="checkbox" ng-model="...">
与一个模型相关联。但在实践中,我们通常希望一个模型存储来自多个复选框的选中值数组。 list 模型无需 Controller 中的额外代码即可解决该任务。您应该使用 <input type="checkbox">
的属性标签:
checklist-model
而不是 ng-modelchecklist-value
- 应该选择什么作为数组项关于javascript - 将值保存到 AngularJS 中 ng-repeat 中复选框上的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45540622/
我是一名优秀的程序员,十分优秀!