简体   繁体   English

在选择下拉列表中使用选定选项的Angular.JS过滤器项目

[英]Angular.JS filter items using selected option in select dropdown

Using the WP API I am outputting a list of posts onto a page from the JSON file. 使用WP API,我正在从JSON文件将帖子列表输出到页面上。 I am trying to filter these posts using an input field and two selects. 我正在尝试使用输入字段和两个选择过滤这些帖子。 Currently I am able to filter the posts through the input field ( searchrecipe ) when I search for a title of a post which works fine. 目前,当我搜索工作正常的帖子标题时,可以通过输入字段( searchrecipe )过滤帖子。

What I have unsure of how to do is filter the posts when I select an option from one of the selects. 我不确定该怎么做,当我从一个选择中选择一个选项时,就过滤帖子。 There are two selects, one which contains all tags used and one which contains all categories. 有两个选择,一个包含所有使用的标签,另一个包含所有类别。

So to be clear, my problem is I do not know how to filter the posts when I select an option from a select drop down. 要明确地说,我的问题是,当我从选择下拉列表中选择一个选项时,我不知道如何过滤帖子。

Any help would be great. 任何帮助都会很棒。 Thanks! 谢谢!

Search: <input ng-model="searchrecipe">

<select ng-model="categories" ng-options="category.name for category in categoryList"></select>
<select ng-model="tags" ng-options="tag.name for tag in tagsList"></select>

<article ng-repeat="post in posts | filter:searchrecipe">
    <h3>
        <a href="{{ post.link }}">
            {{ post.title }}
        </a>
    </h3>
    <p ng-repeat="category in post.terms.category">
        {{category.name }}
    </p>
    <p ng-repeat="tag in post.terms.post_tag">
        {{ tag.name }}
    </p>
</article>

Just replace your html: 只需替换您的html:

     Search: <input ng-model="searchrecipe">

     <select ng-model="category" ng-options="category.name for category in categoryList"></select>
     <select ng-model="post_tag" ng-options="post_tag.name for post_tag in tagsList"></select>

     <article ng-repeat="post in posts | filter:searchrecipe | filter:category.name | filter:post_tag.name ">
        <h3>
           <a href="{{ post.link }}">
              {{ post.title }}
           </a>
        </h3>
        <p ng-repeat="category in post.terms.category">
           {{category.name }}
        </p>
        <p ng-repeat="tag in post.terms.post_tag">
           {{ tag.name }}
        </p>
     </article>

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

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