问题
The code below has been copied from UI5 Demo Kit but while I run it, the console is showing the error message that the function Fragment.load
is not a function. Please suggest any alternative or highlight issue if any.
sap.ui.define([
"sap/ui/core/mvc/Controller",
"sap/m/MessageToast",
"sap/ui/model/Filter",
"sap/ui/model/FilterOperator",
"sap/ui/model/json/JSONModel",
"sap/m/MessageToast",
"sap/ui/core/Fragment"
], function(Controller, MessageToast, Filter, FilterOperator, JSONModel, Fragment) {
"use strict";
return Controller.extend("Workspace.controller.HelloPanel", {
onInit: function() {
var plant = {
pid: "",
ptype: "",
pdesc: "",
psite: "",
pstatus: "",
passigned: "",
pattach: ""
};
var oModel1 = new JSONModel(plant);
this.getView().setModel(oModel1, "SUP");
},
onOpenDialog: function() {
var oView = this.getView();
if (!this.byId("helloDialog")) {
Fragment.load({
id: oView.getId(),
name: "Workspace.view.HelloDialog",
controller: this
}).then(function(oDialog) {
// connect dialog to the root view of this component (models, lifecycle)
oView.addDependent(oDialog);
oDialog.open();
});
} else {
this.byId("helloDialog").open();
}
},
onCloseDialog: function() {
this.byId("helloDialog").close();
},
});
});
回答1:
For other readers: if you're getting the same error, keep in mind that Fragment.load
api is available only as of 1.58.
To see which UI5 version the app is runnig with, press Ctrl+Shift+Left Alt+P.
For the question author: you have required the module "sap/m/MessageToast"
twice.
sap.ui.define([ "sap/ui/core/mvc/Controller", "sap/m/MessageToast", "sap/ui/model/Filter", "sap/ui/model/FilterOperator", "sap/ui/model/json/JSONModel",
"sap/m/MessageToast",// <-- Remove it "sap/ui/core/Fragment" ], /*...*/);
The 2nd MessageToast
needs to be removed. Otherwise, you're trying to call .load()
from a MessageToast
, hence the error.
来源:https://stackoverflow.com/questions/55287847/uncaught-typeerror-fragment-load-is-not-a-function