简体   繁体   中英

Angular JS ng-options to access object inside object not working

I am trying to create couple select buttons that will be dynamic, and for the first one it worked fine using ng-options.

<select ng-options="muscles.name for muscles in bigdata.muscles track by muscles.id" ng-model="selected"></select>

Now as for the second one, it simple didnt work, or didnt print.

<select ng-options="exercises.name for exercises in bigdata.exercises" ng-model="selected"></select>

and the third one, printed the full array, instead of separating it.

   <select ng-options="reps for reps in bigdata.muscles.reps" ng-model="selected"></select>

My Json file looks like this:

{   
"name": "Gym App",
"muscles":[
        {
            "id":1,
            "name": "chest",
            "reps": [4,6,7,8,9,10,11,12],
            "weight": [2,4,6,8,10,12,16,18,20,22,24,26,28,30],
            "image": "img/muscles/chest.jpg",
            "exercises": [
                {
                    "name": "ALTERNATING FLOOR PRESS",
                    "rating": 6.1
                }, (and goes on with exercises)...

Do objects inside objects need to be treated different?

Thanks

There are some mistakes. muscles is array, not object.

2) replace from bigdata.exercises to bigdata.muscles[0].exercises

3) replace from bigdata.muscles.reps to bigdata.muscles[0].reps

Then, it will work

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