Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Meteor模板查询更改,如何更改数据库中的内容?_Javascript_Templates_Meteor - Fatal编程技术网

Javascript Meteor模板查询更改,如何更改数据库中的内容?

Javascript Meteor模板查询更改,如何更改数据库中的内容?,javascript,templates,meteor,Javascript,Templates,Meteor,我和meteor在一个博客上工作,我已经进入了搜索部分:现在我想根据搜索条件更改模板变量的数据。到目前为止,我还不知道如何使要在模板中呈现的数据重新排序 以下是我现在拥有的: HTML <template name="posts"> {{#each post}} <div class = "postWrapper"> <p>{{postTitle}} - <small><em>{{userName}}<e

我和meteor在一个博客上工作,我已经进入了搜索部分:现在我想根据搜索条件更改模板变量的数据。到目前为止,我还不知道如何使要在模板中呈现的数据重新排序

以下是我现在拥有的: HTML

<template name="posts">
   {{#each post}}
     <div class = "postWrapper">
     <p>{{postTitle}} - <small><em>{{userName}}<em></small></p>
     <p><small>{{postDate}}</small><p>
     <div class="postText">{{safe 'postText'}}</div>
     <br/>
     </div>
   {{/each}}
</template>
如何更改Template.posts.post查询,使其按时间戳以外的内容进行排序。当触发事件时,我对Template.posts.post查询所做的任何更改都将一无所获

  Template.searchForm.events = {
    "click .cancelBtn": function(){
       $("#lightbox-container, #searchForm, #postForm").hide();
    },
    "click #searchBtn": function(){
        var reply = TestPosts.find({}, {sort: {timeStamp: 1}});
            //what do I need here to be able to change the posts returned 
            //to the template?
    }
  }

我试图使用meteor.render,但它没有任何效果。任何指导都是很好的。

你应该开始更“反应性”地思考,而不是循序渐进地思考。如果有帮助的话,反应性思维有点像陈述性思维。只需声明你想看什么,让Meteor知道怎么看,什么时候看

考虑到这一点,这可能适合您(使排序顺序成为会话变量):


我没想到会这样,这变化很大。谢谢你抽出时间。
  Template.searchForm.events = {
    "click .cancelBtn": function(){
       $("#lightbox-container, #searchForm, #postForm").hide();
    },
    "click #searchBtn": function(){
        var reply = TestPosts.find({}, {sort: {timeStamp: 1}});
            //what do I need here to be able to change the posts returned 
            //to the template?
    }
  }
Session.setDefault('sortOrder', {'timestamp': -1});
Template.posts.post = function(){
   return TestPosts.find({}, {sort: Session.get('sortOrder'), limit: 100});
}

Template.searchForm.events = {
  "click .cancelBtn": function(){
     $("#lightbox-container, #searchForm, #postForm").hide();
  },
  "click #searchBtn": function(){
      Session.set('sortOrder', {'timestamp': 1});
  }
}