Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何转换此路由器路由?_Javascript_Meteor_Routes_Iron Router - Fatal编程技术网

Javascript 如何转换此路由器路由?

Javascript 如何转换此路由器路由?,javascript,meteor,routes,iron-router,Javascript,Meteor,Routes,Iron Router,在IronRouter.js文件中,我有一条到家的路由,定义如下: Router.route('/', { name: 'home', waitOn: function() { return [ Meteor.subscribe('infosContainers'), Meteor.subscribe('infosMachines'), Meteor.subscribe('alertes'),

在IronRouter.js文件中,我有一条到家的路由,定义如下:

  Router.route('/', {
      name: 'home',
      waitOn: function() {
        return [
          Meteor.subscribe('infosContainers'),
          Meteor.subscribe('infosMachines'),
          Meteor.subscribe('alertes'),
        ];
      },
      fastRender: true,
    });
然后我想将其转换为这种定义,但是
waitOn
不起作用,并创建了一个错误:

Router.route('/', function(){
  this.layout('layout');
  this.render('home');
  this.next();
  waitOn: function() {
    return [
      Meteor.subscribe('infosContainers'),
      Meteor.subscribe('infosMachines'),
      Meteor.subscribe('alertes'),
    ];
  };
  fastRender: true;
});

那么如何将其转换为第二个定义呢?

您将waitOn属性放在函数声明中,这是错误的javascript语法,请将其转换为以下方式:

Router.route('/', {
  fastRender: true,
  subscriptions: function() {
    return [
      Meteor.subscribe('infosContainers'),
      Meteor.subscribe('infosMachines'),
      Meteor.subscribe('alertes'),
    ];
  },
  action: function() {
    if (this.ready()) {
      this.layout('layout');
      this.render('home');
    }
  }
});

Iron router guide:

谢谢你的回答,但是订阅服务器不是这样工作的,你能帮我吗?@Jerome我刚对代码做了更改,你错过了检查
this.ready()
,还有
this.next()
仅当您希望下一次匹配处理请求时才应调用router@Jerome本指南将向您展示许多示例