我见过类似的问题,但不能将其应用到我的情况......流星杀出渲染两次
我有一个路线定义与iron-router
:
this.route('home', {
path: '/',
template: 'home',
waitOn: function(){
return [Meteor.subscribe('books'),Meteor.subscribe('authors'))];
},
onBeforeAction: function(){
Session.set('search_keywords', this.params.search);
}
});
在我home.js
文件我有一个助手来显示books
这样的:
Template.booksList.helpers({
books: function() {
if(Session.get("search_keywords")){
keywords = new RegExp(Session.get("search_keywords"), "i");
var result = Books.find({$or:[{name:keywords},{description:keywords},{tags:keywords}]},{sort: {updatedAt: 1}});
if(result.count()===0){
console.log('no results found')
return [];
}else{
return result;
}
}
}
});
和home.html
:
<template name="booksList">
<div class="row">
{{#each books}}
{{> bookDetail}}
{{/each}}
</div>
</template>
我们的目标是通过像http://mydomain.com/?search=Happy%20Potter
这样的URL访问视图来查找所有哈利波特的书籍。
东西我不明白...页面呈现两次,首先说没有结果,然后显示结果。 你明白为什么了吗?
谢谢!
是的,这是正常的。如果你不喜欢,那么你可以查看iron-router的'loadTemplate'选项,它会显示一个不同的模板直到你'waitOn'的数据已经到达。 –