[英]Apply filter based on select list - Angular JS
Array 1: Categories -> Category_Name, Category_Id 数组1:类别->类别名称,类别ID
Array 2: Items -> Item_name ... etc , Category_Belonging_Id 数组2:项目->项目名称...等,Category_Belonging_Id
I need to filter shown items based on selected category. 我需要根据所选类别过滤显示的项目。
<div class="list>
<select>
<option ng-repeat="category in categories" ng-model="category_type">
{{category.Category_Name}}
</option>
</select>
<a ng-repeat="item in items | filter: // What should I put here?" href="#">
...
</a>
</div>
Assuming you have: 假设您有:
Catergory = {
id
name
}
and 和
MeatType{
id
catergoryId
name
}
You can do something like 你可以做类似的事情
<a ng-repeat="item in meatTypes | filter: {categoryId : catergory_type.id}" href="#">
first of all you should use ng-option
instead of ng-repeat
like 首先,您应该使用
ng-option
而不是ng-repeat
<select ng-model="category_type" ng-options="category.Category_Name for category in categories"></select>
and use filter
like 并使用
filter
像
filter:{Category_Belonging_Id:category_type.Category_Id }
尝试这个
<a ng-repeat="item in meatTypes | filter: {Category_Belonging_Id:category_type.Category_Id }" href="#">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.