In order to enable triggering methods (e.g. event handlers, formatters, ...) from a fragment, the controller instance (this
) or a plain object should be assigned to the option controller
when creating the fragment. With the API loadFragment
(available since 1.93), the controller instance is added as a listener object by default.
Given this
as a reference to the current controller instance:
Since UI5 1.93
this.loadFragment({ name: "my.Fragment" });
In the above API, the id
and controller
are this.getView().getId()
and this
by default respectively. And the loaded fragment is added to the dependents
aggregation of the view automatically as well (unless addToDependents: false
).
No need to assign them explicitly.
Since UI5 1.58
// Fragment required from "sap/ui/core/Fragment"
Fragment.load({
id: this.getView().getId(),
name: "my.Fragment",
controller: this, // or a plain object that contains the event handlers
});
UI5 1.56 and below
// Deprecated!
sap.ui.xmlfragment(this.getView().getId(), "my.Fragment", this);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…