Angular JS选择过滤器
我有一个创建搜索模块,可以使用输入类型文本进行搜索..现在我想在表单中添加选择选项以搜索过滤它
以下是Plunker:http://embed.plnkr.co/yPJADtUDcgU720dx8ChJ/preview
答案 0 :(得分:1)
您可以从json中提取类别,然后删除重复:
//Filter all the categories, return an array of duplicated categories
var allCategories = json.modules.map(function(item) {
return item.category;
});
//Remove the duplication from the first array
var filteredCategories = [];
allCategories.forEach(function(item) {
if (filteredCategories.indexOf(item) < 0) {
filteredCategories.push(item);
}
});
//Assign the filtered array to scope
$scope.categories = filteredCategories;
也改变html:
<select ng-model="search.category" ng-options="category for category in categories"></select>
答案 1 :(得分:0)
只需使用ng-model =“搜索”,就像这样:
<select ng-model="search" ng-options="module.category for module in ocw.modules"></select>