【问题标题】:Filter elements of an ng-repeat list from another ng-repeat list从另一个 ng-repeat 列表中过滤 ng-repeat 列表的元素
【发布时间】:2020-06-28 13:30:52
【问题描述】:

我只有一个显示标题、描述和类别的数组。
由于我不知道类别(因为用户可以添加自己的类别),所以我使用 ng-repeat 做了类别列表,同样显示项目。
而且我需要能够使用两个过滤器过滤的项目:使用按标题过滤的文本输入(这个非常好用)和类别按钮(不起作用)。

以下是我对类别进行 ng-repeat 的方式:

<div class="list_categories">
 <!-- I put 'ng-repeat-start' and 'ng-repeat-end' to be able to add the value "checked" to the first input -->
 <!-- it wasn't working and @tbone849 already helped me with that-->
 <label ng-click="clearAll()" ng-repeat-start="x in categories" ng-if="$first">
   <input type="radio" id="optradio" name="optradio" ng-model="searchCategory.Category" value="{{x}}" checked="checked">
   <p>{{x}}</p>
 </label>
 <label ng-click="clearAll()" ng-repeat-end ng-if="!$first">
   <input type="radio" id="optradio" name="optradio" ng-model="searchCategory.Category" value="{{x}}">
   <p>{{x}}</p>
 </label>
</div>

这是项目的 ng-repeat:

<div class="card" ng-repeat="x in items | filter:searcher | filter:searchCategory" >
  <div class="title-space">
    <h2>{{x.Title}}</h2>
  </div>
  <div class="description-space">
    <p>{{x.Description}}</p>
  </div>
</div>

有关我的代码的更多详细信息,我在 this Plunker 中做了一个工作示例。
我希望有人可以帮助我使类别过滤器起作用。

【问题讨论】:

    标签: javascript angularjs angularjs-ng-repeat angularjs-filter


    【解决方案1】:

    使用 ng-checked 来处理检查第一个选项。

    <label ng-click="clearAll()" ng-repeat="x in categories">
        <input type="radio" id="optradio" ng-model="searchCategory.Category" name="optradio" ng-value="{{x}}"  ng-checked="$first">
       <p>{{x}}</p>
    </label>
    

    【讨论】:

    • 谢谢,真的很管用..我的主要问题是过滤问题有什么想法吗?
    • 他们能按一个类别或多个类别搜索吗?
    • 检查我做的 Plunker 示例,我做了一个包含类别的数组并用它来创建 de 类别列表。
    • 尝试将过滤器参数更改为 searchCategory.category
    • 我想已经是这样了,收音机输入有ng-model="searchCategory.category"
    猜你喜欢
    • 1970-01-01
    • 2020-02-05
    • 2017-01-28
    • 1970-01-01
    • 2016-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多