How To Use `oevent` When Loading Fragment Asynchronously?
I'm able to used oEvent when using this code: onPressDialog: function(oEvent) { if (!this._oDialog) { this._oDialog= sap.ui.xmlfragment('idDialog', 'com.Dialog', this);
Solution 1:
As explained in the linked answer above, the oEvent
parameters are completely reset after the event handler (onPressDialog
) is executed. I.e. after the fragment is fetched asynchronously, the oEvent
object won't contain the same references / parameter values anymore. Try storing the target reference in a closure variable before creating the fragment, and then use the variable when the promise is finally resolved.
Given <Dialog id="myDialog">
in the fragment definition:
Since UI5 1.93
onPressDialog: asyncfunction(oEvent) {
const myEventValue = oEvent.get/*...*/; // to use later without relying on oEventconst oDialog = this.byId("myDialog") || awaitthis.loadFragment({ name: "com.Dialog" });
// ... Do something with myEventValue ...
oDialog.open();
},
Since UI5 1.58
onPressDialog: asyncfunction(oEvent) {
const myEventValue = oEvent.get/*...*/; // to use later without relying on oEventlet oDialog = this.byId("myDialog");
if (!oDialog) {
oDialog = awaitFragment.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();
},
Post a Comment for "How To Use `oevent` When Loading Fragment Asynchronously?"