我有对话框的片段。我有:
<Button text="{i18n>buttonClose}" press="onCloseDialog"/>
在控制器中有:
openDialog: function () {
if (!this.pressDialog1) {
this.pressDialog1 = sap.ui.xmlfragment("mypackage.fragment.Dialog", this);
}
this.pressDialog1.open();
},
onCloseDialog: function () {
this.pressDialog1.close();
},
当我在控制台中调试它时,它进入
openDialog
函数,但是当我尝试关闭它时,它不进入onCloseDialog
。我还注意到控制台中有一个警告:event handler function "onCloseDialog" is not a function or does not exist in the controller.
为什么它不进入
onCloseDialog
功能?@编辑
openDialog的名称如下:
var controllerName = "mypackage.ProdE"
sap.ui.controller(controllerName, {
openDialog: function () {
if (!this.pressDialog1) {
this.pressDialog1 = sap.ui.xmlfragment("mypackage.fragment.Dialog", this)
this.getView().addDependent(this.pressDialog1);
}
this.pressDialog1.open();
},
onCloseDialog: function () {
this.pressDialog1.close();
});
最佳答案
原因很简单,您的Dialog未连接到控制器,因此不会执行您已实现的onCloseDialog方法。
这是处理对话框的正确方法:
onOpenDialog: function(oEvent) {
if ( !this._oDialog ) {
this._oDialog = sap.ui.xmlfragment(this.getView().getId(), "mypackage.fragment.Dialog", this);
// This is important becuase your dialog will be attached to the view lifecycle
this.getView().addDependent(this._oDialog);
}
this._oDialog.open();
},
ondialogClose: function(oEvent) {
// Do cleaning stuff
this._oDialog.close();
}