sap.ui.core.Fragment.load 返回未定义

Tin*_*hen 2 fragment sapui5

我的应用中有两个 FLP 磁贴。一个可以访问sap.ui.core.Fragment.load,但另一个不能。

  • 工作一:

在此处输入图片说明

  • 不工作的一个:

在此处输入图片说明

byId返回一个懒惰的存根在此处输入图片说明

他们都通过

<script
  id="sap-ui-bootstrap"
  src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
  data-sap-ui-theme="sap_belize_plus"
  data-sap-ui-libs="sap.m, sap.ushell, sap.collaboration"
  data-sap-ui-preload="async"
  data-sap-ui-compatVersion="edge"
  data-sap-ui-frameOptions='allow'
  data-sap-ui-resourceroots='{
    "monitor": "./",
    "common": "./../../../common"
  }'>
</script>
Run Code Online (Sandbox Code Playgroud)

Fragment.jsSAPUI5 资源中没有不工作的资源,但我可以访问Fragment-dbg.js

在此处输入图片说明

我也对比过manifest.json,没有区别。有没有其他线索?

Tin*_*hen 5

I found that after sap.ui.xmlfragment(), Fragment.load() exists. So add it to sap.ui.define or .require, then it works.

sap.ui.require([
  "sap/ui/core/Fragment"
], function(Fragment){
  Fragment.load({
    name: "namespace.myFragment",
    controller: this
  }).then(function(oFragment) {
    // ...
  }.bind(this));
}.bind(this));
Run Code Online (Sandbox Code Playgroud)

Thanks to @Boghyon Hoffmann:

the factory functions inside the sap.ui.* namespace have also been refactored. UI5 now provide fully asynchronous APIs on top. The old APIs are of course still available for compatibility reasons, but are also deprecated. Modularization of the SAPUI5 Core

New API must use modular way, which means use sap.ui.require / sap.ui.define.


Documentation: Legacy Factories Replacement