sap.ui.core.Fragment.load returns 未定义

sap.ui.core.Fragment.load returns undefined

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

byId returns一个惰性存根

他们都通过

加载UI5
<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>

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

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

我发现在sap.ui.xmlfragment()之后,Fragment.load()存在。 所以将它添加到sap.ui.define.require,然后就可以了。

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

感谢@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

新API必须使用模块化方式,即使用sap.ui.require / sap.ui.define.


文档:Legacy Factories Replacement