角JS加复选框值到一个数组 [英] angular js add value of checkboxes to an array
本文介绍了角JS加复选框值到一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的code:
<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-真值
只接受字符串,所以你需要使用一种解决方法。这已经有一段时间功能要求。在此期间,你可以这样做:
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-模型
来引用该对象的关键。你可以使用默认的真/假
复选框值:
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
检查真正
。
这篇关于角JS加复选框值到一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文