How to clear dialog/xmlfragment content after close?

前端 未结 3 1163
闹比i
闹比i 2021-01-29 04:45

My dialog is defined as document:

  onOpenDialog : function () {
     var oView = this.getView();
     var oDialog = oView.byId(\"helloDialog\");
     // create         


        
3条回答
  •  北荒
    北荒 (楼主)
    2021-01-29 05:03

    Dialog XML

    
        
            
    

    Create the Dialog

    if(!this._oDialog){
        this._oDialog = sap.ui.xmlfragment("idFragment","Path_to_your_Dialog", this);           
    }
    

    You need to use destroy() of the sap.ui.core.Element.

    dialogAfterclose: function(oEvent) {
        this._oDialog.destroy();
    }
    

    As per your code

    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.
    }
    

    Ref: sap.ui.core.Element - destroy()

提交回复
热议问题