Javascript 从该视图中创建新的主干视图
如何从该视图中创建新的主干视图?例如当关闭Javascript 从该视图中创建新的主干视图,javascript,backbone.js,Javascript,Backbone.js,如何从该视图中创建新的主干视图?例如当关闭ModalDialog2时,我的视图ModalDialog1需要(重新)实例化自身 define('ModalDialog1.View', [ 'modal_dialog1.tpl' , 'ModalDialog2.View' , 'Backbone' , 'underscore' ], function( modal_dialog1_tpl , Mo
ModalDialog2
时,我的视图ModalDialog1
需要(重新)实例化自身
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 {
}
}
})
});
您可以使用相关视图的构造函数
var modalDialog1 = new self.constructor();
modalDialog1.showInModal();
第二种选择是,当modalDialog2
关闭时,使用一种方法初始化modalDialog1