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

如何在SAPUI5中调整对话框大小后触发事件?

  •  0
  • MJBZA  · 技术社区  · 6 年前

    我有一个sap.m.对话。

    调整对话框大小后,我需要触发事件处理程序。

    如何在SAPUI5中的对话框没有resize事件时注册此事件处理程序。

    2 回复  |  直到 6 年前
        1
  •  2
  •   rcedillo    6 年前

    根据文件 sap.m.Dialog 有一个 可调整大小 允许 sap.m.对话框 拥有 调整处理程序大小 。如果将该属性设置为 真的 你可以用 sap.ui.core.ReisizeHandler 去处理那件事。

    见下文 example 也在jsbin上。

    var oDialogResize = new sap.m.Dialog('resizableDialog', {
                title: "Resizable Dialog",
                resizable: true,
                content: [
                    new sap.m.Label("label1",{text: ""}),
                    new sap.m.ToolbarSpacer(),
                    new sap.m.Label("label2",{text: ""})
                ],
                endButton: new sap.m.Button('resizeDialogCloseButton', {
                    text: "Cancel", press: function () {
                        oDialogResize.close();
                    }
                })
            });
    
    
    
    var oButton = new sap.m.Button({
      text: 'Open',
      press: function() {
        oDialogResize.open();
      }
      
    }).placeAt('content');
    
    oButton.addEventDelegate({
         "onAfterRendering": function () {
              sap.ui.core.ResizeHandler.register(oDialogResize, function(oEvent){
                console.log("ResizeEvent");
                sap.ui.getCore().byId("label1").setText(" W:" + oEvent.size.width);
                 sap.ui.getCore().byId("label2").setText(" H: " + oEvent.size.height);
              });
         }
    }, this);
    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8">
        <title>JS Bin</title>
        <script 
                src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js" 
                id="sap-ui-bootstrap" 
                data-sap-ui-theme="sap_bluecrystal" 
                data-sap-ui-xx-bindingSyntax="complex" 
                data-sap-ui-libs="sap.m"></script>
      </head>
      <body class="sapUiBody">
        <div id='content'></div>
      </body>
    </html>
        2
  •  1
  •   alexP    6 年前

    向对话框中添加事件侦听器:

    this.myDialog.attachBrowserEvent("resize", function(){ 
      console.log("Resize done");
    });
    
    this.myDialog.open();