ng-options按另一个下拉列表中的值过滤一个数据

时间:2015-05-21 20:59:56

标签: javascript angularjs ng-options

我在ng-options filter by value in another dropdown中读到了一些例子。

但在我的情况下,数据在一个范围内。

我试过

Make:
<select ng-model="makeng" ng-options="option.id as option.display for option in makes">
    <option ng-disabled="true"  ng-selected="true" value="">Select a make</option>
</select>


Model:
<select ng-model="modelng" ng-options="option.data.name for option in makes | filter:{id:makeng}">
    <option ng-disabled="true"  ng-selected="true" value="">Select a model</option>
</select>

Plnkr:http://plnkr.co/edit/MlbBcVso57H3tyVEJa8o?p=preview

1 个答案:

答案 0 :(得分:1)

根本不需要过滤器:

http://plnkr.co/edit/OjM1yJPYV1vQh5HRDNQ1?p=preview

请:

<select ng-model="makeng" ng-options="option as option.display for option in makes">
    <option ng-disabled="true"  ng-selected="true" value="">Select a make</option>
</select>

型号:

<select ng-model="modelng" ng-options="option.name for option in makes[makes.indexOf(makeng)].data">
    <option ng-disabled="true"  ng-selected="true" value="">Select a model</option>
</select>