AngularJS 将复选框的值添加到数组 [英] AngularJS add value of checkboxes to an array
本文介绍了AngularJS 将复选框的值添加到数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个代码:
<tr ng-repeat="doc in providers">
<td><input type="checkbox" ng-true-value="{{doc.provider.Id}}" ng-false-value="" ng-model="ids"></td>
</tr>
{{ids}}
我想获取数组上复选框的值
i want to get the values of the checkboxes on an array
推荐答案
ng-true-value
只接受字符串,因此您需要使用一种解决方法.这是功能请求已有一段时间了.同时,您可以这样做:
ng-true-value
only accepts strings so you'll need to use a workaround. This has been a feature request for some time. In the meantime, you can do this:
在控制器中创建一个 ids
对象,例如:
Create an ids
object in the controller like:
$scope.ids = {};
并更改 ng-model
以引用该对象中的键.您可以使用默认的 true/false
复选框值:
and change ng-model
to reference a key in that object. You can use the default true/false
checkbox values:
<td><input type="checkbox" ng-model="ids[doc.provider.Id]"></td>
然后您可以遍历 ids
中的键,检查 true
.
Then you can loop over the keys in ids
checking for true
.
这篇关于AngularJS 将复选框的值添加到数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文