Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
449 views
in Technique[技术] by (71.8m points)

tree - Angularjs: ng-options group by

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>



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"}
]


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 ]


See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...