【问题标题】:onRendered data not appearing unless I hit back button除非我点击返回按钮,否则不会出现 onRendered 数据
【发布时间】:2018-06-13 17:04:19
【问题描述】:

我想在每次渲染时运行 onRendered 事件中的一些功能。

Template.DashboardCoachPost.onRendered(function () {
  var post, postId;

  this.autorun(function() {
    postId = Router.current().params.query.p;
    reactive.isSubmitted.set(false);

    if (Template.instance().subscriptionsReady()) {
      post = Posts.find({_id: postId}).fetch()[0];
      reactive.post.set(post);

      if (post) {
        reactive.isSubmitted.set(true);  
      }
    }
  });
});

在我的 RouterController 我有:

DashboardCoachPostController = RouteController.extend({
  subscriptions: function() {
    this.postId = Router.current().params.query.p;

    if (this.handle) {
      this.handle.stop();
    }

    if (this.postId) {
      this.handle = this.subscribe('posts', { postId: this.postId });
    }
  }
});

还有我的路线:

Router.route('/dashboard/coach/post', {
    name: 'dashboardCoachPost',
    controller: DashboardCoachPostController,
    where: 'client',
    layoutTemplate: 'LegalLayout'
});

我感觉我没有正确处理订阅,但如果没有这种方法,我无法弄清楚如何获取我的帖子。

【问题讨论】:

    标签: meteor iron-router


    【解决方案1】:

    Template.instance().subscriptionsReady() 用于subscribe in a template instance。但你是subscribing in the router

    您必须选择是让模板实例处理订阅还是让路由器处理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-15
      • 1970-01-01
      • 2011-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多