流星js Iron-router waitOn并用作渲染数据 [英] meteorjs iron-router waitOn and using as data on rendered

查看:10
本文介绍了流星js Iron-router waitOn并用作渲染数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在我的 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并用作渲染数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆