admin管理员组文章数量:1414929
i'm playing with Marionette first time. After re-rendering ItemViews, their events not triggered. Simple example:
App = new Marionette.Application;
App.addRegions({
headerRegion: '#header',
contentRegion: '#content',
});
App.addInitializer(function () {
this.Views = {
MainMenu : new MainMenuView(),
ContentOne : new ContentOneView(),
ContentTwo : new ContentTwoView(),
};
});
App.addInitializer(function () {
var self = this;
var eva = self.vent;
eva.listenTo(self.Views.MainMenu, 'content1', function () {
self.contentRegion.show(self.Views.ContentOne);
});
eva.listenTo(self.Views.MainMenu, 'content2', function () {
self.contentRegion.show(self.Views.ContentTwo);
});
});
App.on('start', function () {
var self = this;
self.contentRegion.show(self.View.ContentOne);
});
App.start();
After re-rendering ContentOneView & ContentTwoView, their events not triggered. What i'm doing wrong?
i'm playing with Marionette first time. After re-rendering ItemViews, their events not triggered. Simple example:
App = new Marionette.Application;
App.addRegions({
headerRegion: '#header',
contentRegion: '#content',
});
App.addInitializer(function () {
this.Views = {
MainMenu : new MainMenuView(),
ContentOne : new ContentOneView(),
ContentTwo : new ContentTwoView(),
};
});
App.addInitializer(function () {
var self = this;
var eva = self.vent;
eva.listenTo(self.Views.MainMenu, 'content1', function () {
self.contentRegion.show(self.Views.ContentOne);
});
eva.listenTo(self.Views.MainMenu, 'content2', function () {
self.contentRegion.show(self.Views.ContentTwo);
});
});
App.on('start', function () {
var self = this;
self.contentRegion.show(self.View.ContentOne);
});
App.start();
After re-rendering ContentOneView & ContentTwoView, their events not triggered. What i'm doing wrong?
Share Improve this question asked Jul 16, 2013 at 23:23 iBoozyVoozyiBoozyVoozy 777 bronze badges3 Answers
Reset to default 5The problem you are having is that region.show()
is going to close any view that is currently occupying that region. Doing so undelegates the view's events. After the initial region.show()
you should manually call render on the view.
You can see this explained here and an issue discussing it here.
I managed to solve this problem by using delegating the events when the view is shown in the layout:
layoutView.content.show(contentView);
contentView.delegateEvents();
Although this is only necessary after the first render as mentioned by Andrew Hubbs
instead of using eva to listen to events that happen on the views, try listening to eva for events passed by other views
App.addInitializer(function () {
var eva = self.vent;
var self = this;
this.listenTo(eva, 'someStringHere', function(){/*do stuff here*/};
});
and then in your views you can trigger events through eva/vent
var eva = self.vent;
eva.trigger("someStringHere");
本文标签: javascriptMarionette ItemView events after rerenderingStack Overflow
版权声明:本文标题:javascript - Marionette ItemView events after re-rendering - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745189595a2646849.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论