AngularJS复选框NG-重复和选择的对象? [英] AngularJS checkbox ng-repeat and selected objects?
问题描述
我想痛苦少做以适当的方式,但我无法弄清楚如何处理NG-模型并将其绑定到选中的列表等,此外我需要填充的稍晚时间列表,保持选定的对象了。
类别= [{名:运动,ID:50d5ad},{名:常规,ID:678ffr} ] <跨度NG重复=类别中的类别>
<标签类=复选框为={{category.id}}>
<输入类型=复选框VALUE ={{category.id}}NG模型=?? NG-点击=?? NAME =组ID ={{category.id}}/>
{{category.name}}
< /标签>
< / SPAN>
我有每个列表中填充,因为它将从一个服务器拉出时间重写的类别。
所以我想我需要有数组,第二个将举行选定的对象?
如果我是正确的,我怎么preSELECT复选框?
我是否需要NG-点击为了调用自定义函数存储另一个阵列中选定的对象?
我是否需要NG-模型复选框,什么?
什么是正确的路痛苦少?
我每次列表中填充覆盖类
因为这将是拉出形式的服务器。所以我quess我需要有
阵列,第二个将举行选定的对象?
块引用>是的,因为它是一个列表,您可以/应该使用数组。有关所选项目/对象的信息应存放在你的范围模型(下面的例子)。
如果我是正确的,我怎么preselected复选框?
块引用>保存ID在模型上选定的选项/复选框的,让
NG-模型
做休息。
我是否需要为了调用自定义函数NG-点击存储选定
其他阵列中的对象?
块引用>没有,你不需要它,
NG-模型
就足够了。
我是否需要在复选框NG-模式?干嘛?
块引用>是的,你需要它。在
NG-模型
负责存储你的模型所选的选项及其制造('pre - ')。选择自动的jsfiddle http://jsfiddle.net/bmleite/PQvQ2/
I am trying to do it in proper way with less pain, but i can't figure out how to deal with ng-model and binding it to the selected list etc and moreover i need to populate that list in later time and keep selected objects in it.
categories = [ { "name": "Sport", "id": "50d5ad" } , {"name": "General", "id": "678ffr" } ] <span ng-repeat="category in categories"> <label class="checkbox" for="{{category.id}}"> <input type="checkbox" value="{{category.id}}" ng-model="??" ng-click="??" name="group" id="{{category.id}}" /> {{category.name}} </label> </span>
I have to override the categories each time the list is populated since it will be pulled out from a server.
So I guess I need to have arrays and the second one will hold the selected objects?
If I am right, how do I preselect checkboxes?
Do I need ng-click in order call custom function to store the selected object in the other array?
Do I need ng-model in checkbox And what for?
What is the proper-way with less pain?
解决方案I have to override the categories each time the list is populated since it will be pull out form server. So i quess i need to have arrays and the second one will hold the selected objects?
Yes, since it is a list you can/should use arrays. The information about the selected items/objects should be stored on your scope model (example below).
If I am right, how do I preselected checkboxes?
Save the ID's of the selected options/checkboxes on your model and let the
ng-model
do the rest.Do I need ng-click in order call custom function to store the selected object in the other array?
No, you don't need it,
ng-model
is enough.Do i need ng-model in check box? And what for?
Yes, you need it. The
ng-model
is responsible for storing the selected options on your model and for making the ('pre-')selection automatic.jsfiddle http://jsfiddle.net/bmleite/PQvQ2/
这篇关于AngularJS复选框NG-重复和选择的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!