AngularJS:过滤下拉指令

AngularJS: filter a dropdown directive

本文关键字:指令 过滤 AngularJS      更新时间:2023-09-26

这是我的代码

如何使用自定义属性筛选下拉指令?

$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筛选下拉列表。

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

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