0
我的渲染方法_initializeLayout之前被稱爲:我們是否需要針對每種佈局的不同事件?
var _initializeLayout = function() {
console.log('initializeLayout...');
Controller.layout = new Layout();
Controller.layout.on("show", function() {
vent.trigger("layout:rendered");
});
vent.trigger('app:show', Controller.layout);
};
我在使用佈局上呈現方法:
// controller attach a sub view/ search View
vent.on("layout:rendered", function() {
console.log('layout:rendered =>StartController');
// render views for the existing HTML in the template, and attach it to the layout (i.e. don't double render)
var inspectorStartView = new InspectorStartView();
Controller.layout.inspector.attachView(inspectorStartView);
var playerStartView = new PlayerStartView();
Controller.layout.player.attachView(playerStartView);
});
當我嘗試它,我上呈現回調_initializeLayout前(叫) 。我把它叫_initializeLayout在路由器/控制器的方法:
Controller.go_inspector_control_center = function(term) {
_initializeLayout();
//vent.trigger("search:term", term);
};
我又跑了一下,發現事件正從不同的控制器的_initializeLayout觸發()方法:
// private
var _initializeLayout = function() {
console.log('initialize Start Layout...');
Controller.layout = new Layout();
Controller.layout.on("show", function() {
**vent.trigger("layout:rendered"); // <--**
});
vent.trigger('app:show', Controller.layout);
};
看樣子事件需要具有獨特的名稱。我會嘗試的。如果有人知道請附和。
安德魯
本例來自Marionette先生本人:MyApp.vent.on(「some:namespaced:event」,function(){ // do stuff }); 在這個例子中,它看起來像你創建你自己的命名空間,但是右端的事件是一個事件名稱。 「命名空間」== some.namespaced,你可以想出你想要什麼 MyApp.vent.trigger(「some:namespaced:event」); – KingAndrew