【问题标题】:Apply filter based on select list - Angular JS根据选择列表应用过滤器 - Angular JS
【发布时间】:2016-07-15 11:54:10
【问题描述】:

数组 1:类别 -> Category_Name、Category_Id

数组 2:项目 -> Item_name ...等,Category_Belonging_Id

我需要根据所选类别过滤显示的项目。

<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>

【问题讨论】:

  • 你能在 jfiddle 上分享这个问题吗

标签: javascript angularjs ionic-framework angularjs-filter


【解决方案1】:

首先你应该使用ng-option 而不是ng-repeat like

<select ng-model="category_type" ng-options="category.Category_Name for category in categories"></select>

并使用filter 喜欢

filter:{Category_Belonging_Id:category_type.Category_Id }

see demo here

【讨论】:

    【解决方案2】:

    假设你有:

    Catergory = {
    id 
    name
    }
    

    MeatType{
        id
        catergoryId
        name
        }
    

    你可以这样做

    <a ng-repeat="item in meatTypes | filter: {categoryId : catergory_type.id}" href="#">
    

    【讨论】:

    • 抱歉,MeatTypes 指的是 Items 的误解。我已经编辑了我的问题。您说的是 category_type.id,但我认为您的意思是 category_type.Category_Id。对吧??
    【解决方案3】:

    试试这个

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

    【讨论】:

      猜你喜欢
      • 2015-11-11
      • 1970-01-01
      • 2020-10-09
      • 1970-01-01
      • 2016-04-07
      • 2013-05-20
      • 2021-09-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多