渲染封闭的木偶视图 [英] Rendering a closed Marionette view
问题描述
封闭的Marionette视图是否应在重新渲染时重新委托已定义的事件(事件,modelEvents,CollectionEvents)?
Shouldn't a closed Marionette view re-delegate the defined events (events, modelEvents, CollectionEvents) when rendering again?
似乎我必须在关闭并重新渲染视图后手动调用委托事件.否则,视图将无法按预期工作.
It seems as if I have to manually call delegateEvents after closing and re-rendering a view. Otherwise the view won't work as expected.
var app = new Marionette.Application();
app.addRegions({
main: '.main'
});
var MyView = Marionette.ItemView.extend({
template: _.template('Hi, I\'m a view! Foo is: <%= foo %>'),
modelEvents: {
'change': 'onChange'
},
onChange: function() {
alert('change!');
}
});
var Model = Backbone.Model.extend({});
app.addInitializer(function() {
var m = new Model({foo: 'bar'});
var myView = new MyView({
model: m
});
app.main.show(myView);
myView.close();
app.main.show(myView);
m.set({foo: 'baz'});
});
$(document).ready(function(){
app.start();
});
推荐答案
如果我正确地理解了您的问题,那么关于此的github问题有多个.
If I understand your question right, there are multiple open github issues about this.
例如:
https://github.com/marionettejs/backbone.marionette/pull/654 https://github.com/marionettejs/backbone.marionette/issues/622
上次我检查时,Derick(《木偶侠》的创建者)并不觉得重用封闭的视图应该是区域应做的事情.
Last time I checked, Derick (the creator of Marionette) didn't feel like reusing closed views should be something regions should do.
所以您可以
- 只需创建一个新视图并显示该视图
- 手动调用委托事件-但是我现在不记得有多个事件绑定的问题,因此请小心一点(现在不在工作,所以不能窥视代码,对不起)
- 编写您自己的区域经理
- 或等待,看看Derick是否将合并其中一个拉取请求
这篇关于渲染封闭的木偶视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!