未捕获的TypeError:Fragment.load不是函数 [英] Uncaught TypeError: Fragment.load is not a function

查看:98
本文介绍了未捕获的TypeError:Fragment.load不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码已从UI5演示工具包复制而来,但是在我运行它时,控制台显示错误消息,提示功能Fragment.load不是函数.请提出任何替代或突出显示的问题.

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:依赖项与所需参数不匹配

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

Reason 1: mismatch of dependencies with required parameters

When calling sap.ui.define or .require, make sure that the dependencies and the callback parameters are listed in the same order:

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...*/) {
  // ...
});

例如,在上面的问题中,我们可以看到偶然地两次需要"sap/m/MessageToast",导致与回调参数列表不匹配.从依赖项列表中删除第二个"sap/m/MessageToast".否则,您将尝试从MessageToast调用.load(),从而导致错误.

In the question above, for example, we can see that "sap/m/MessageToast" is accidentally required twice, resulting in a mismatch with the list of callback parameters. Remove the 2nd "sap/m/MessageToast" from the dependency list. Otherwise, you're trying to call .load() from the MessageToast, hence the error.

如果尽管具有正确的依赖顺序,也遇到相同的错误,请记住UI5引入了

If you're getting the same error, despite having the correct dependency order, keep in mind that UI5 introduced Fragment.load first in 1.58.

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

To see which UI5 version the app is actually running with, press Ctrl+Shift+Left Alt+P.

这篇关于未捕获的TypeError:Fragment.load不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆