简体   繁体   中英

Having trouble getting ng-options to work with my data

I have created a quick plunker with what I am trying to do.

What I am trying to achieve is, when a user clicks on one of the two items in list, the main header of each will be added to the menu bar.

For Example, the main header of Central Pulse, is New Zealand.

http://plnkr.co/edit/5WSLCrssOGrf7XbV6TvX

This is my select that I use:

<select ng-model="selectBox" ng-options="dataV.name for dataV in data"></select>

I have also tried, 'dataV as dataV.name for dataV in data'

And my object contains:

{"name":type,"children":[]}

Since data is an object and not an array, the correct syntax for ng-options is one of the following :

label for (key , value) in object
select as label for (key , value) in object
label group by group for (key, value) in object
select as label group by group for (key, value) in object

For example, you can use :

ng-options="dataV as dataV.name for (dataKey,dataV) in data"

See also here for more details

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM