【问题标题】:Meteor JS: Dynamic Layout TemplateMeteor JS:动态布局模板
【发布时间】:2015-06-23 22:52:58
【问题描述】:

我想让布局模板动态化。布局模板的值将使用 Meteor.call 'getLayoutTemplate' 在服务器中获取。我应该把 Meteor.call 放在哪里?它应该等到它获取 Meteor.call 的值。有什么想法吗?

Router.configure
  layoutTemplate: ????
  notFoundTemplate: 'notFound'

【问题讨论】:

  • 我的第一个想法是,将其放入 Session-Variable。
  • @DanielBudick 那是个好主意。但是我应该把 Meteor.call 放在哪里呢?因为该会话变量的值将来自服务器(Meteor.call)

标签: javascript node.js meteor coffeescript iron-router


【解决方案1】:

我会将方法调用放在onAfterAction 挂钩中,然后根据调用结果设置layoutTemplate

Router.route('/route', {
  name: 'route',
  onAfterAction: function() {
    var routerInstance = this;
    Meteor.call('method', function(error, result) {
      routerInstance.layoutTemplate = result;
    });
  }
});

【讨论】:

  • 我尝试了你的建议,但 onAfterAction 确实被解雇了
  • 我刚刚在一个现有的项目中尝试过,它可以工作。控制台中是否有任何错误消息?
  • 我做了一个要点gist.github.com/ccfiel/6e73182113224118cdba。控制台中没有错误。有什么想法吗?
  • 你的服务器方法返回了什么?还要注意服务器方法中的异步事物,因为您希望在客户端得到答案,因此您需要从服务器返回一些内容。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-24
  • 1970-01-01
  • 1970-01-01
  • 2013-04-08
  • 2014-04-01
  • 1970-01-01
相关资源
最近更新 更多