关闭后如何清除对话框/xmlfragment 内容? [英] How to clear dialog/xmlfragment content after close?
本文介绍了关闭后如何清除对话框/xmlfragment 内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的对话被定义为文档:
onOpenDialog : function () {
var oView = this.getView();
var oDialog = oView.byId("helloDialog");
// create dialog lazily
if (!oDialog) {
// create dialog via fragment factory
oDialog = sap.ui.xmlfragment(oView.getId(), "sap.ui.demo.wt.view.HelloDialog");
oView.addDependent(oDialog);
}
oDialog.open();
}
假设这个对话框有很多 Input/Select/ComboBox 等,用户在里面输入,关闭,导航到另一个主条目和详细信息页面,再次打开这个对话框实例,信息仍然在这里.如果我想在每次用户关闭时清除信息/输入怎么办?
Let's say this dialog has many Input/Select/ComboBox and so on, user inputs in it, close, nav to another master item and detail page, open this dialog instance again, and the information is still here. What if I want to clear the information/inputs every time user closes it?
关闭后销毁此对话框是解决此问题的唯一方法吗?
Is destroy this dialog after close the only way to solve this?
推荐答案
Dialog XML
<Dialog afterClose="dialogAfterclose" >
<beginButton>
<Button text="yes" press="confirmOk"/>
</beginButton>
<endButton>
<Button text="no" press="confirmCancel"/>
</endButton>
</Dialog>
创建对话框
if(!this._oDialog){
this._oDialog = sap.ui.xmlfragment("idFragment","Path_to_your_Dialog", this);
}
你需要使用sap.ui.core.Element
的destroy()
.
dialogAfterclose: function(oEvent) {
this._oDialog.destroy();
}
根据您的代码
onOpenDialog : function () {
var oView = this.getView();
if (!this._oDialog) {
this._oDialog = sap.ui.xmlfragment(oView.getId(), "sap.ui.demo.wt.view.HelloDialog");
oView.addDependent(this._oDialog);
}
this._oDialog.open();
},
dialogAfterclose: function(oEvent) {//function called after Dialog is closed
this._oDialog.destroy();//destroy only the content inside the Dialog
},
confirmOk: function(oEvent) {
this._oDialog.close();//Just close the Dialog, Dialog afterClose() will be called and destroy the Dialog content.
}
参考:sap.ui.core.Element - destroy()
这篇关于关闭后如何清除对话框/xmlfragment 内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文