简体   繁体   中英

Loading customer sapui5 library inside component.js

According to the documentation here:

I build the following folder structure with following files:

  • /my/themes/sap_bluecrystal/library.css
  • /my/library.js
  • /my/Square.js

Now I am asking me how to load the library (inside Component.js) correct. I tried following in Component.js

jQuery.sap.registerModulePath("my", "./my");

And in some View:

jQuery.sap.require("my.Square");
...
new my.Square({
 text : "Test",
 size : "200px"
})

All in all the Square control seems to be usable but the library.js and library.css is not loaded at all.

Any idea how to do it right?

Using bootstrap XML code inside index.html would not work if the app is running inside Fiori Launchpad.

Bonus question: Where to deploy a custom library inside SAP to be usable by multiple apps? One idea (but maybe that's wrong) is to create a BSP application just containing the library code?

The right way to load the library would be (instead of jQuery.sap.require):

sap.ui.getCore().loadLibrary("my");

This will load a "library-preload.json" file (if available) and also include the theme resources.

See https://openui5.hana.ondemand.com/#docs/api/symbols/sap.ui.core.Core.html#loadLibrary

First question I could solve for my own: Replace

jQuery.sap.require("my.Square");

with

jQuery.sap.require("my.library");

Second question is still open :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM