问题描述
我尝试在我的 Template.rendered
函数中获取返回的数据.
I try to get the returned data in my Template.rendered
function.
当前代码为:
this.route('editCat', {
layoutTemplate : 'layoutCol2Left',
template : 'modCategoriesEdit',
path : '/mod/categories/edit/:_id',
yieldTemplates : _.extend(defaultYieldTemplates, {
'navigationBackend' : {to : 'contentLeft'}
}),
waitOn : function () {
return Meteor.subscribe('oneCat', this.params._id);
},
data : function () {
return Categories.findOne({_id : this.params._id});
}
});
在这个块中,我等待 Collection Document
的订阅并将文档作为数据返回.
In this block i wait on the subscribtion of the Collection Document
and return the Document as data.
现在我可以像这样在我的模板中使用返回的文档:
Now i can use the returned Document in my Template like this:
<template name="modCategoriesEdit">
<h1>Edit {{name}}</h1>
</template>
我的问题是我必须像这样在渲染函数中使用返回的数据:
My problem is that i have to use the returned data in my rendered function like this:
Template.modCategoriesEdit.rendered = function () {
console.log(this.data);
}
但这会返回null".
But this returns "null".
所以我的问题是:如何访问渲染函数中返回的数据?
So my question is:How is it possible to get access to the returned data in the rendered function ?
推荐答案
解决方案:
只需将以下内容添加到您的 Iron-router route() 方法中即可.
Just add the following to your iron-router route() method.
action : function () {
if (this.ready()) {
this.render();
}
}
模板会在所有加载正确后呈现.
Than the Template will rendered after all is loaded correctly.
这篇关于流星js Iron-router waitOn并用作渲染数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!