【发布时间】:2014-02-25 17:54:00
【问题描述】:
我正在用流星写博客,我已经进入搜索部分:现在我想根据搜索条件更改模板变量的数据。到目前为止,我不明白如何使将要在模板中呈现的数据重新排序。
这是我现在拥有的: 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>
Javascript
Template.posts.post = function(){
return TestPosts.find({}, {sort: {timeStamp: -1}, limit: 100});
}
如何更改 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 但它什么也没做。任何指导都会很棒。
【问题讨论】:
标签: javascript templates meteor