错误:Fragment.load()不是调试器中的函数

问题描述 投票:1回答:1

下面的代码是从sap ui5 demokit复制的,但是当我运行它时,调试器显示函数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();
    },

  });
});
sapui5
1个回答
2
投票

对于其他读者:如果您遇到同样的错误,请记住Fragment.loadapi仅在1.58版本可用。


对于提问作者:您需要两次模块"sap/m/MessageToast"

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"
], /*...*/);

需要删除第二个MessageToast。否则,你试图从.load()调用MessageToast,因此错误。

© www.soinside.com 2019 - 2024. All rights reserved.