简体   繁体   中英

angularjs option list becoms empty when i select an option

I am working on a django-tastypie api application where i am using angularjs as JavaScript framework.what I am doing is i have a list of curriculum objects where each curriculum object contains a list of grades objects and each of grade object contains a list of subjects. my data structure is as

{'id':1,
'name':'cbse',
'grades':[{'id':10,
            'name':'matriculation',
            'subjects':[
                        {'id':1,'name':'science'},
                        {'id':2,'name':'Math'},
                        {'id':3,'name':'English'}
                       ]
        }

I am using this data structure where each object carries it's releted object . I want to place these object in select box where so that choosing one object loads the other objects in the select fields . as if i use cbse from curriculum, all the grades into that objects loaded into the grades select option box. but the problem is when i select an option from curriculum select box it becomes empty.
my HTML is as follow

<label>Select Curriculum</label>
    <select ng-model="qt_curriculumlist" ng-options=" curriculum.name for curriculum in qt_curriculumlist" ng-change="loadGrades()">
</select></br>
<label>Select Grade</label> 
<select ng-model="qt_gradeslist" ng-options="grade.name for grade in qt_gradelist " ng-change="loadSubjects()">
</select>
<label>Select Subject</label>
<select ng-model="qt_syllabuslist" ng-options="subject.name for subject in qt_subject_list" ng-change="loadTopics()">
</select>

first times curriculum loaded correctly to the options field but after selecting an option list becomes empty.

That's because you set your ng-model the same as your list.

You should use a different variable for the model.

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