简体   繁体   English

根据选择列表应用过滤器-Angular JS

[英]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 }

see demo here 在这里查看演示

尝试这个

<a ng-repeat="item in meatTypes | filter: {Category_Belonging_Id:category_type.Category_Id }"   href="#">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM