Arrays 如何在AngularJS中将复选框值添加到数组中?
谁来帮帮我! 假设我有一个复选框列表,每个复选框都有一个ID。 我想要$scope一个带有复选框ID的数组Arrays 如何在AngularJS中将复选框值添加到数组中?,arrays,angularjs,checkbox,Arrays,Angularjs,Checkbox,谁来帮帮我! 假设我有一个复选框列表,每个复选框都有一个ID。 我想要$scope一个带有复选框ID的数组 <div ng-app="myapp"> <div ng-controller="ctrlParent"> <table> <tr ng-repeat="(key, value) in providers"> <td><input type="checkbox" ng-m
<div ng-app="myapp">
<div ng-controller="ctrlParent">
<table>
<tr ng-repeat="(key, value) in providers">
<td><input type="checkbox" ng-model="ids[value.Id]"> {{value}} </td>
</tr>
</table>
{{ids}}
</div>
现在我的数组输出(如果选中了所有复选框)是:{“5”:true,“6”:true,“8”:true,“10”:true}
我想:[{Id:5},{Id:6},{Id:8},{Id:10}]这是一个可能的解决方案:
<input type="checkbox" ng-model="ids[$index]" ng-true-value="
{{value}}" ng-false-value="{{undefined}}"/>{{value}}
{{value}}
{{ids}}
添加ng true value指令将解决此问题
在控制器中,将ID从对象更改为数组
退房。是的,这正是我想要的。谢谢。来吧,这是我提供的相同解决方案,提前10分钟完成上述相同的解决方案
<input type="checkbox" ng-model="ids[$index]" ng-true-value="
{{value}}" ng-false-value="{{undefined}}"/>{{value}}
<input type="checkbox" ng-model="ids[$index]" ng-true-value="{{value}}" >