代码之家  ›  专栏  ›  技术社区  ›  Michu93

onCloseDialog不会关闭对话框

  •  0
  • Michu93  · 技术社区  · 7 年前

    我有一个片段中的对话。我有:

    <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();
        });
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   IObert StErMi    7 年前

    这是处理对话框的正确方法:

    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();
    }
    
    推荐文章