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

时间:2019-03-21 19:20:28

标签: sapui5

以下代码已从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();
    },

  });
});

1 个答案:

答案 0 :(得分:2)

对于其他读者:如果您遇到相同的错误,请记住,Fragment.load api 仅在(自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,因此出现错误。