我有片段中的对话框。我有:
<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
功能?
@EditopenDialog 的调用方式如下:
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();
});
原因很简单,您的对话框未附加到控制器,因此它不会执行您实现的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();
}