我有一个sap.m.Dialog。
我需要在调整对话框大小后触发事件处理程序。
如何在SAPUI5中的Dialog没有resize事件时注册此事件处理程序。
根据文档,sap.m.Dialog有一个可调整大小的属性,允许sap.m.Dialog有一个resize处理程序。如果你将该属性设置为True,你可以使用sap.ui.core.ReisizeHandler来处理该事件。
在jsbin上也可以看到下面的example。
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>
向对话框添加事件侦听器:
this.myDialog.attachBrowserEvent("resize", function(){
console.log("Resize done");
});
this.myDialog.open();