I have tried reading the SAPUI5 documentation for the above but I am not able to clearly understand its usage. Also what is the difference between sap.ui.localResources()
and jQuery.sap.registerModulePath()
and when to use what?
If someone can explain with an easy example it will be really helpful. Also can we use jQuery.sap.registerModulePath()
to load mockData?
If you were using resourceRoots
either in the bootstrap config or in the app descriptor, you've been using jQuery.sap.registerModulePath
all the time as each key-value pair, defined in resourceRoots
, is passed as arguments to that static method.
For example, you may have something like this in your index.html:
<script id="sap-ui-bootstrap" src="..."
data-sap-ui-resourceroots='{"my.app": "./"}'
...
></script>
UI5 then registers the namespace ("my.app"
) globally as a reference saying "Whenever that name is mentioned while resolving other module names, I should look for the target module in the registered path" which is "./"
relative to the current document.location.href
in our case.
The above code is the same as calling jQuery.sap.registerModulePath("my.app", "./")
[1] directly.
"../"
instead of "./"
which is needed if the project has another *.html file in one hierarchy level deeper such as mockserver.html
custom/control/somewhere/c3/chart/
, we can register another namespace: "my.app.c3chart": "./custom/control/somewhere/c3/chart"
and then
xmlns:c3="my.app.c3chart"
instead of
xmlns:c3="my.app.custom.control.somewhere.c3.chart"
."my.app.c3chart"
can still be used everywhere.[1]: As of 1.58, the API is deprecated. When registering namespaces manually, the API sap.ui.loader.config
should be used:
sap.ui.loader.config({
paths: {
"my/anotherApp": "https://example.com/somePath/anotherApp"
}
});
What is the difference between sap.ui.localResources() and jQuery.sap.registerModulePath()?
Here is the current source code of what sap.ui.localResources
actually does:
sap.ui.localResources = function(sNamespace) {
jQuery.sap.registerModulePath(sNamespace, "./" + sNamespace.replace(/\./g, "/"));
};
That's it. It calls jQuery.sap.registerModulePath
right away with the dots in the namespace (if any) replaced with "/"
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With