Meteor - Iron Router无法提供的数据

时间:2015-10-22 12:43:51

标签: meteor iron-router

我正在努力实现一些非常简单的事情:加载模板并用数据填充它。但是,模板会多次渲染,第一次使用null数据。

我发现了关于这个问题的各种帖子,说明每次订阅将记录添加到客户端数据库时都会发生渲染,并尝试应用建议的解决方案,但我仍然没有数据的第一次渲染。我该如何解决这个问题?

Router.configure({
    layoutTemplate: 'layout',
    loadingTemplate: 'loading',
    notFoundTemplate: 'notFound'
});

Router.route('/team/:_id/cal', {

    name: 'calendar',
    waitOn: function() {
        return [
            Meteor.subscribe('userTeams',Meteor.user()._id),
            Meteor.subscribe('teamUsers', this.params._id)];
    },
    action : function () {
        console.log("action:"+this.ready());
        if (this.ready() && Template.currentData != null) {
            this.render();
        }
    },
    data: function(){
        var team = Teams.findOne({_id:this.params._id})
        console.log(JSON.stringify(team));
        return team;
    }
}

);

控制台输出

Navigated to http://localhost:3000/team/PAemezbavGEmWBNMy/plan
router.js:33 undefined
router.js:33 {"_id":"PAemezbavGEmWBNMy","name":"superteam","createdAt":"2015-10-22T11:51:10.994Z","members":["T6MpawQj75J2HgPi6","4T3StXAaR9iF4sK99","dDe2dJq3wjL2rFB43"]}
router.js:26 action:true
router.js:33 {"_id":"PAemezbavGEmWBNMy","name":"superteam","createdAt":"2015-10-22T11:51:10.994Z","members":["T6MpawQj75J2HgPi6","4T3StXAaR9iF4sK99","dDe2dJq3wjL2rFB43"]}

0 个答案:

没有答案