2016-03-04 67 views
1

我想如果用waitOn任何认购数据,通过以下方式,是什么waitOn下认购收集的差异,订阅和onBeforeAction

waitOn:function(){ 
    Meteor.subscribe('//some published function) 
} 

使用onBeforeAction喜欢的区别

Router.onBeforeAction : function(){ 
    Meteor.subscribe('//some published function) 
} 

个使用订阅

subscriptions: function() { 
    this.subscribe('items'); 
    } 

回答

0

如果你想只为授权用户发布数据,您检查(如果用户进行身份验证)的路线,在onBeforeAction是可能的。喜欢的东西:

Router.map(function(){ 

    this.route('home', { 
    path : '/', 
    template : 'home' 
    }); 

    this.route('register', { 
    path : '/register', 
    template : 'register' 
    }); 

    this.route('login', { 
    path : '/login', 
    template : 'login' 
    }); 

    this.route('requestlisting', { 
    path : '/requestlisting', 
    template : 'requestlisting', 
    waitOn : function(){ 
     return Meteor.subscribe('RequestsPublication'); 
    } 
    }); 
    ... 
}); 

var requireLogin = function() { 
    if(!Meteor.user()){ 
     if(Meteor.loggingIn()){ 
      this.render(this.loadingTemplate); 
     }else{ 
      Router.go('login'); 
     } 
    } else { 
     this.next(); 
    } 
} 

Router.onBeforeAction(requireLogin, {only: ['requestlisting',...]}); 

在这个例子中,在onBeforeAction,路由发生了“requestlisting”只有当用户登录后,话很有道理订阅任何数据。

+0

感谢槟榔这么一个简洁的解释,但'订阅'呢? –