AngularJS:过滤下拉指令

时间:2013-09-03 23:50:01

标签: javascript angularjs

Here is my code

如何使用自定义属性过滤我的下拉指令?

$scope.myKeyword = [
        {Id: 1, Keyword:"ActivityType", Description: "Active"}, 
        {Id: 2, Keyword:"ActivityType", Description: "InActive"}, 
        {Id: 3, Keyword:"ActivityType", Description: "Deleted"},
        {Id: 4, Keyword:"MarketSegment", Description: "Fashion"},
        {Id: 5, Keyword:"MarketSegment", Description: "IT"},
        {Id: 6, Keyword:"MarketSegment", Description: "F&B"},
        {Id: 7, Keyword:"MarketSegment", Description: "Manufacturing"},
    ];

指令标记

<keywords supplier-id="supplier.Id" keyword-type="MarketSegment"  title="Choose Status" label="" array="myKeyword" opt-value="Id" opt-description="Description"></keywords>

我想通过提供的MarketSegment过滤下拉列表。

1 个答案:

答案 0 :(得分:1)

我找到了解决方案,只需在指令模板中添加filter:keywordType即可。这是更新link

<select ng-model="supplierId" ng-options="a[optValue] as a[optDescription] for a in array | filter: keywordType" required>'