我寫了一個使用Mongodb和鐵的MeteorJS的小代碼:路由器(我是MeteorJS的新手)。一切工作正常,並在最後,排序停止工作。要多解釋一下,網站列表必須根據收到的讚譽和創建日期進行排序。下面是代碼的有關章節:排序在流星JS
//Sorting websites based on userfilter or votes
websites:function(){
if (Session.get("userFilter")){
return Websites.find({ createdBy: Session.get("userFilter") }, { sort: { createdOn: -1, up: -1 }});
} else {
return Websites.find({},{ sort: { createdOn: -1, up: -1 }});
}
},
{{#each websites}}
<div class="col-xs-12 col-md-3">
<div class="thumbnail">
<a href="{{url}}" class="site_name">{{title}}</a>
<p class="site_desc">{{description}}</p>
<br>
<p class="upvote_button">Upvote: {{up}}</p>
<p class="downvote_button">Downvote: {{down}}</p>
<a href="#" class="btn btn-default js-upvote" id="upvote_button">
<span class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span>
</a>
<a href="#" class="btn btn-default js-downvote" id="downvote_button">
<span class="glyphicon glyphicon-arrow-down" aria-hidden="true"></span>
</a>
<br>
<p class="added-by">Added By:
<a href="#" class="js-filter">{{getUser createdBy}}</a>
</p>
<p>Added On: {{createdOn}}</p>
<a href="/single_website/{{_id}}">Details</a>
</div>
</div>
{{/each}}