0
什麼是處理訂閱數據的最佳方式。例如,你有一個遊戲,你必須先創建角色,然後才能做任何其他事情。目前我認爲我可以嘗試使用onBeforeAction
過濾器來處理它。所以我爲每個需要角色的路線設置了一個全局控制器。如何處理流星/鐵路路由器訂閱
DefaultController = LayoutController.extend({
onBeforeAction : function() {
var currentCharacter = Character.getCurrent.call({});
if(currentCharacter === undefined) {
this.render('CharacterCreate');
} else {
this.next();
}
},
waitOn() {
this.subscribe('characters.owned');
}
});
你有一個這樣的路線:
Router.route('/game', { controller: 'DefaultController' });
的問題是,直到集合被加載遊戲的模板將顯示。有沒有更好的方法?還有另一個問題,當一個路由需要一個字符時,它將引發一個異常,直到訂閱被加載。
鏈接作品很好謝謝 – Kani