未捕获的类型错误:Fragment.load 不是函数

96r*_*ain 2 amd sapui5

下面的代码是从 UI5 Demo Kit 复制的,但是当我运行它时,控制台显示该函数Fragment.load不是函数的错误消息。请提出任何替代方案或突出问题(如果有)。

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();
    },

  });
});
Run Code Online (Sandbox Code Playgroud)

Bog*_*ann 6

原因 1:依赖项与所需参数不匹配

调用sap.ui.defineor 时.require,请确保依赖项和回调参数相同的顺序列出

sap.ui.define([ // list of dependencies
  "sap/ui/core/mvc/Controller", // 1st
  "sap/m/AnotherModule", // 2nd
  // etc...
], function(/*required modules: */Controller/*1st*/, AnotherModule/*2nd, etc...*/) {
  // ...
});
Run Code Online (Sandbox Code Playgroud)

例如,在上面的问题中,我们可以看到不"sap/m/MessageToast"小心需要两次,导致与回调参数列表不匹配。"sap/m/MessageToast"从依赖项列表中删除 2nd 。否则,您将尝试.load()从 MessageToast调用,因此会出现错误。


原因2:该方法在以后的版本中引入

如果您遇到相同的错误,尽管具有正确的依赖顺序,请记住 UI5 是Fragment.load1.58中首先引入的。

要查看应用实际运行的 UI5 版本,请按Ctrl+ Shift+ Left Alt+ P