下拉列表中的过滤器集合更改

时间:2014-12-28 17:40:02

标签: meteor

我试图在下拉列表更改中过滤我的收藏,这是我在模板管理器中的代码

  Template.postsList.events({
    "change .typeselection": function(e, t){
      console.log("drop changed");
      return Session.set("type", $("[name=type]").val());
    }
  });

这是我的模板代码:

  <template name="postsList">
   <select name="type" id="type"  value="" placeholder="type the adress" class="form-control typeselection">
            <option value="Restaurant">Restaurant</option>
             <option value="Hotel">Hotel</option>
             <option value="Shop">Shop</option>
        </select> 

  <div class="posts">
    {{#each postsWithRank}}
      {{> postItem}}
    {{/each}}

    {{#if nextPath}}
      <a class="load-more" href="{{nextPath}}">Load more</a>
    {{else}}
      {{#unless ready}}
        {{> spinner}}
      {{/unless}}
    {{/if}}
  </div>
</template>

1 个答案:

答案 0 :(得分:1)

根据我的理解,此代码适合您

//on dropdown change we are setting the new value in session
Template.postsList.events({
        "change .typeselection": function(e, t){
          console.log("drop changed");
          Session.set("type", $("[name=type]").val());//no need to return anything here
        }
      });




 //whenever the session variabe changes this code will re run
    Template.postsList.helpers({
        "postsWithRank": function(){
          //assuming you have type field in your collection and you want filter on that field
          return Posts.find({"type":Session.get("type")});
        }
      });



//so this code will display the selected relative data
 {{#each postsWithRank}}
  {{> postItem}}
{{/each}}