简体   繁体   English

当我选择一个选项时,angularjs选项列表将变为空

[英]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. 我正在django-tastypie api应用程序上工作,我正在使用angularjs作为JavaScript框架。我正在做的是我有一个课程表对象列表,其中每个课程表对象都包含一个成绩对象列表,每个年级对象都包含一个列表对象科目。 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. 就像我从课程中使用cbse一样,进入该对象的所有成绩将加载到成绩选择选项框中。 but the problem is when i select an option from curriculum select box it becomes empty. 但是问题是当我从“课程选择”框中选择一个选项时,它变成空的。
my HTML is as follow 我的HTML如下

<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. 那是因为您将ng-model设置为与列表相同。

You should use a different variable for the model. 您应该为模型使用其他变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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