As shown in the figure below:

<script id="sap-ui-bootstrap"
    src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
    data-sap-ui-theme="sap_bluecrystal"
    data-sap-ui-libs="sap.m, sap.ui.comp"
    data-sap-ui-bindingSyntax="complex" 
    data-sap-ui-compatVersion="edge"
    data-sap-ui-preload="async"
    data-sap-ui-resourceroots='{
        "sap.ui.demo.CombineLatest": "./"
    }'>
</script>

When I first learned SAP UI5, I was confused about the function of data-sAP-UI-resourceRoots.

Browse the entire SAP UI5 project resource we developed, whether it’s component.js:



Again, the View Controller:

And the view id itself contains sap.ui.demo.Com bineLatest prefix:

If we remove the data-sap-ui-resourceRoots directive from index.html:

You will find that the application will not load at all. The Chrome Developer Tools report a number of errors that the resource files will not load.

Pick one of the error messages and analyze it. Now the load path of Component.js is:

https://sapui5.hana.ondemand….

This path is obviously inherited from the SAP UI5 library file defined in index. HTML with id sap-ui-bootstrap SRC attribute:

Component of our engineering documents. Js, whose id for sap.ui.demo.CombineLatest.Com ponent:

The SAP UI5 framework converts an ID to a URL when it loads:

sap/ui/demo/CombineLatest/Component.js,

Then, in its header, concatenate the prefix from the SAP UI5 library file defined by the SRC attribute with id sAP-ui-bootstrap:

https://sapui5.hana.ondemand….

The final path:

https://sapui5.hana.ondemand….

Obviously, this path is wrong. Because Component.js only exists in our project itself.

So you need to use the data – SAP – UI – resourceroots tell SAP UI5 loader, if there are any prefix for sap.ui.demo.Com bineLatest local resource file, Don’t use SAP – UI – core. Js prefix is https://sapui5.hana.ondemand… Instead, use the local path./

After modification, resource loading is successful, the correct path should be: http://localhost:3002/combine/Component.js

Where did this path come from?

(1) Component. Js id for sap.ui.demo.CombineLatest.Com ponent, because the data – SAP – UI – resourceroots effect, Will sap.ui.demo.CombineLatest.Com ponent replace. / Component

(2)./Component is replaced with the URL: /Component.js

(3)./ The previous URL is localhost:3002/combine

Get the last absolute path to load Component.js:

http://localhost:3002/combine/Component.js

More of Jerry’s original articles can be found on “Wang Zixi “: