一尘不染

Angular.js:ng-options分组依据

angularjs

我有这种一级树情况:

<select ng-model="tipost" 
        ng-options="tip.DESC group by tip.TIPIS for tip in tipall"><br>
</select>

json在哪里:

[
  {"ID":"1", "IDPARENT":"0", "TIPIS":"", "DESC":"GroupName1"},
  {"ID":"2", "IDPARENT":"1", "TIPIS":"GroupName1", "DESC":"CHILDNAME1"},
  {"ID":"3", "IDPARENT":"0", "TIPIS":"", "DESC":"GroupName2"}
]

问题在于,这会与孩子一起创建optgroup,但也会重复其根:

- GroupName1
- GroupName2
[ GroupName1 ]
- CHILDNAME1
[ GroupName2 ]

我想生产:

[ GroupName1 ]
- CHILDNAME1
[ GroupName2 ]

阅读 193

收藏
2020-07-04

共1个答案

一尘不染

如果您将json更改为以下内容,则分组将无法完全实现:

[
 {"ID":"1", "TIPIS":"GroupName1", "DESC":"name"},
 {"ID":"2", "TIPIS":"GroupName1", "DESC":"name1"},
 {"ID":"3", "TIPIS":"GroupName2", "DESC":"name2"},
 {"ID":"4", "TIPIS":"GroupName1", "DESC":"name3"},
]

然后,您将按照想要的方式进行分组

jsFiddle:http :
//jsfiddle.net/rtCP3/182/

2020-07-04