1 回答
TA贡献1805条经验 获得超9个赞
oEvent
在事件处理程序(onPressDialog
)执行后,参数被完全重置。即异步获取片段后,该oEvent
对象将不再包含相同的引用/参数值。尝试在创建片段之前将目标引用存储在闭包变量中,然后在最终解决 Promise 时使用该变量。
<Dialog id="myDialog">
片段定义中给出:
从 UI5 1.93 开始
使用APImyController.loadFragment
(推荐)
onPressDialog: async function(oEvent) {
const myEventValue = oEvent.get/*...*/; // to use later without relying on oEvent
const oDialog = this.byId("myDialog") || await this.loadFragment({ name: "com.Dialog" });
// ... Do something with myEventValue ...
oDialog.open();
},
从 UI5 1.58 开始
使用APIFragment.load
onPressDialog: async function(oEvent) {
const myEventValue = oEvent.get/*...*/; // to use later without relying on oEvent
let oDialog = this.byId("myDialog");
this.getOwnerComponent().runAsOwner(function() {
if (!oDialog) {
oDialog = await Fragment.load({ // Fragment required from "sap/ui/core/Fragment"
id: this.getView().getId(),
name: "com.Dialog",
controller: this,
});
this.getView().addDependent(oDialog);
}
// ... Do something with myEventValue ...
oDialog.open();
}.bind(this));
},
添加回答
举报