我注意到我的路由器定义并不等待yieldTemplates的订阅完成,而是等待主模板。是否有一种方法可以让产量模板也在waitOn上等待
路由:
Router.route('/', {
template : 'main',
layoutTemplate: 'appLayout',
waitOn: function () {
// return one handle, a function, or an array
return [Meteor.subscribe('userInformation'), Meteor.subscribe('projects')];
},
data: function () {
return Meteor.user();
},
action: function () {
if (this.ready()) {
this.render();
} else {
this.render('login');
}
},
yieldTemplates: {
'dash': {to: 'side'}
}
});我在我的dash模板中使用了data属性,最初它返回undefined。谢谢
发布于 2015-03-01 08:20:43
我认为该语法已被弃用,文档使用此语法来定义that模板:
this.render('dash', {to: 'side'});使用这种语法从来没有遇到过waitOn问题,试一试吧?
发布于 2015-03-19 23:14:38
尝试使用contentFor模板/助手将内容从主模板呈现到布局区域中,而不是在路由器中使用yieldTemplates。
首先从Router.route中删除yieldTemplates。然后,在主模板中添加一个{{> contentFor}}模板:
<template name="main">
{{> contentFor region="side" template="dash"}}
</template>或者,您可以使用contentFor的帮助程序版本
<template name="main">
{{#contentFor 'side'}}
{{> dash}}
<!-- and anything else you want to include -->
{{/contentFor}}
</template>下面是一个演示此方法的MeteorPad:http://meteorpad.com/pad/QCo3JsFLr6R438izF/Leaderboard
有关contentFor的更多信息可以在iron-router文档中找到:
此外,在更新版本的Iron-Router (我使用的是1.0.7)中,yieldTemplates现在已经被yieldRegions所取代,但是这里指定的模板仍然不等待waitOn()函数。
https://stackoverflow.com/questions/27843764
复制相似问题