我有一个对话框,其中有一部分。我在那里:
<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();
});
答案 0 :(得分:2)
原因很简单,您的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();
}