ng-options,过滤器不工作

时间:2015-05-20 09:12:10

标签: javascript angularjs filter ng-options

我在我的HTML中有一个选择(moreCourses是我的控制器的名称):

<select class="form-control" ng-options="course.courseId as course.courseName for course in moreCourses.coursesToshow track by course.courseId | filter: {show: true}" ng-model="course.newcourse" data-ng-change="moreCourses.showCourse(course)">
    <option style="display:none" value="">Choose a course</option>
</select>

这是包含select:

对象的数组
var coursesToshow =
        [{
            courseName: 'English for Work',
            courseId: 'en-efw',
            show: true
        },
        {
            courseName: 'Practice Courses',
            courseId: 'en-practice',
            show: true
        },
        {
            courseName: 'English for Doctors',
            courseId: 'en-efd',
            show: true
        }];

一切正常,但过滤器不起作用,当用户选择一个选项时,属性的值'变为'false',我已经检查过了。

感谢。

1 个答案:

答案 0 :(得分:2)

感谢@Numyx,解决方案是select的订单,在track by

之后应为filter
<select class="form-control" ng-options="course.courseId as course.courseName for course in moreCourses.coursesToshow | filter: {show: true} track by course.courseId" ng-model="course.newcourse" data-ng-change="moreCourses.showCourse(course)">
    <option style="display:none" value="">Choose a course</option>