Angularjs:NG选项与组 [英] Angularjs: ng-options with group
本文介绍了Angularjs:NG选项与组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的一个层次树的情况:结果
I have this one level tree situation:
<select ng-model="tipost"
ng-options="tip.DESC group by tip.TIPIS for tip in tipall"><br>
</select>
结果
结果
其中,JSON是:结果
where the json is:
[
{"ID":"1", "IDPARENT":"0", "TIPIS":"", "DESC":"GroupName1"},
{"ID":"2", "IDPARENT":"1", "TIPIS":"GroupName1", "DESC":"CHILDNAME1"},
{"ID":"3", "IDPARENT":"0", "TIPIS":"", "DESC":"GroupName2"}
]
结果
结果
的问题是,这产生与他们的孩子,但重复进行optgroups
根太:结果
结果
the problem is that this creates the optgroups with their children but repeats
the roots too:
- GroupName1
- GroupName2
[ GroupName1 ]
- CHILDNAME1
[ GroupName2 ]
结果
我想制作:结果
i want to produce:
[ GroupName1 ]
- CHILDNAME1
[ GroupName2 ]
结果
在此先感谢。结果
推荐答案
分组并不很喜欢的工作,如果你改变你的JSON来是这样的:
The grouping doesn't quite work like that, if you change your json to something like this:
[
{"ID":"1", "TIPIS":"GroupName1", "DESC":"name"},
{"ID":"2", "TIPIS":"GroupName1", "DESC":"name1"},
{"ID":"3", "TIPIS":"GroupName2", "DESC":"name2"},
{"ID":"4", "TIPIS":"GroupName1", "DESC":"name3"},
]
然后你会得到分组你想要的方式。
Then you'll get the grouping the way you want
的jsfiddle: http://jsfiddle.net/rtCP3/182/
jsFiddle: http://jsfiddle.net/rtCP3/182/
这篇关于Angularjs:NG选项与组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文