javascript 如何销毁片段(或视图)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24447030/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 02:49:16  来源:igfitidea点击:

How can I destroy a fragment (or a view)?

javascriptsapui5

提问by padibro

I have created this fragment:

我创建了这个片段:

var dialogFrafment = sap.ui.xmlfragment(
    "appIntra.fragment.dialog",
    this.getView().getController() // associate controller with the fragment            
);
this.getView().addDependent(dialogFrafment);
sap.ui.getCore().byId("idMailReport").setValue(sap.ui.getCore().getModel("mailUser"));

dialogFrafment.
dialogFrafment.open();

How can I delete it after it is complete?

完成后如何删除?

回答by Haojie

Store your dialogFrafment in your controller.

将您的 dialogFrafment 存储在您的控制器中。

if(!this.dialogFrafment) {
    this.dialogFrafment = sap.ui.xmlfragment(
        "appIntra.fragment.dialog",
        this.getView().getController() // associate controller with the fragment            
    );
    this.getView().addDependent(dialogFrafment);
    sap.ui.getCore().byId("idMailReport").setValue(sap.ui.getCore().getModel("mailUser"));
}  
this.dialogFrafment.open();

Destroy the fragment in onExit function of your controller.

销毁控制器 onExit 函数中的片段。

onExit: function() {
    if (this.dialogFrafment) {
        this.dialogFrafment.destroy(true);
    }

},