我在流星項目中使用鐵路由器。我想要做的只是在頁面上的特定嵌套模板(即使用我waitOn正在等待的數據的內容區域)內顯示我的loading模板,而不是像Router.onBeforeAction('loading');
那樣代替整個頁面。Iron-Router:我可以定位一個特定的嵌套模板來顯示我的loading模板嗎?
是否有可能使用鐵路由器做到這一點?
我的簡化代碼:
的layout.html
<template name="layout">
{{> yield}}
</template>
<template name="foo">
//bunch of intro text
{{> bar}}
//a big CTA
</template>
<template name="bar">
{{this.something}}
</template>
我想要做的就是與loadingTemplate更換bar
模板,直到數據被加載。頁面的其餘部分可以渲染。 這裏的默認方式,當然,顯示loadingTemplate代替整個頁面(如'富「):
router.js
Router.configure({
layoutTemplate: 'layout',
notFoundTemplate: 'notFound',
loadingTemplate: 'loading'
});
//Router.onBeforeAction('loading'); //Future SO visitors: use this to show the loading template on all routes, if that's what you desire. I only want to show the loading template on one route.
this.route('home', {
path: '/',
action: function() {
if (this.ready()) // is there a short-hand version btw?
this.render();
else
this.render('loading');
},
onBeforeAction: function() {
//this.render('loading'); //shouldn't this be the short-hand version? Doesn't work.
},
waitOn: function() {
return Meteor.subscribe('baz');
},
data: function() {
return Baz.find();
}
});
如果我要找的ISN」 t鐵路由器的可能性,任何建議的替代品是最受歡迎的。謝謝!
對於未來的訪問者,這裏是鐵路由器docs。
我怎麼會在確保只有裝載模板產量'酒吧'模板?並感謝澄清重新行動/ onBeforeAction ...非常有幫助。 –
模板呈現在收益率中; '你的意思是'模板只在'bar'模板中產生?''您可以通過'yieldTemplates','loadingTemplate','notFoundTemplate'和'layoutTemplate'參數(參見上面的示例)來控制哪些內容。'yieldTemplates'中列出的模板將進入指定的命名產量;所有其他(加載,notFound,'home')將進入* main *收益率,即沒有名稱的收益率(只是'{{> yield}}')。 –
您的評論,「'加載'模板將只加載主要收益」是有幫助的。在我的情況下,我只想'加載'模板只加載到'bar'模板中,因此這將是我的主要收益('{{> yield}}')。這意味着我必須將所有其他區域定義爲區域。所以在我的示例代碼,在'layout'模板我不得不定義頁眉和頁腳區域,然後在'foo'模板我不得不定義'//...a一堆介紹文字'和'//...大CTA'作爲區域。然後,我必須使用'yieldTemplates'來在右側區域生成正確的模板。那對嗎? –