如何在该视图中创建新的Backbone视图?例如;当ModalDialog1
关闭时,我的观点ModalDialog2
需要(重新)实例化。
define('ModalDialog1.View',
[
'modal_dialog1.tpl'
, 'ModalDialog2.View'
, 'Backbone'
, 'underscore'
],
function(
modal_dialog1_tpl
, ModalDialog2View
, Backbone
, _
)
{
'use strict';
return Backbone.View.extend({
template: modal_dialog1_tpl
, events: {
'click a[data-modal-id="why-need-info"]': 'openModalDialog2'
}
, openModalDialog2: function() {
var self = this;
var closeCallback = function() {
// How to reinstantiate this view/self??
var modalDialog1 = new self();
modalDialog1 .showInModal();
}
var view = new ModalDialog2View({closeCallback: closeCallback})
.showInModal();
// On calling showInModal the current modal view (this) is destroyed
}
, getContext: function()
{
return {
}
}
})
});
答案 0 :(得分:1)
您可以使用相关视图的构造函数。
var modalDialog1 = new self.constructor();
modalDialog1.showInModal();
第二个选项是在modalDialog1
关闭时有一个初始化modalDialog2
的方法。