sapui5 - When to use jQuery.sap.registerModulePath() with an example? -
hi have tried reading sapui5 documentation above not able understand usage. difference between sap.ui.localresources() , jquery.sap.registermodulepath() , when use what?
if can explain easy example helpful. can use jquery.sap.registermodulepath() load mockdata?
if using resourceroots
either in bootstrap config or in app descriptor, you've been using jquery.sap.registermodulepath
time each key-value pair, defined in resourceroots
, passed arguments static method.
for example, may have in index.html:
data-sap-ui-resourceroots='{ "my.app": "./" }'
ui5 registers namespace ("my.app"
) globally reference saying "whenever name mentioned while resolving other module names, should target module in registered path ("./"
) relative current document.location.href
.".
the above code same calling jquery.sap.registermodulepath("my.app", "./")
directly.
- here, can pass user-defined url prefix. e.g.:
"../"
instead of"./"
needed if project has *.html file in one hierarchy level deeper such mockserver.html - if we've module in deeper hierarchy, e.g. in
custom/control/somewhere/c3/chart/
, can register namespace:"my.app.c3chart": "./custom/control/somewhere/c3/chart"
,- use shortcut example in xmlview definition:
xmlns:c3="my.app.c3chart"
instead ofxmlns:c3="my.app.custom.control.somewhere.c3.chart"
. - reduce maintenance costs changing registered path when module file changes hierarchy level. namespace
"my.app.c3chart"
can still used everywhere.
- use shortcut example in xmlview definition:
- if project not huge, hardly need call
jquery.sap.registermodulepath
directly.
what difference between sap.ui.localresources() , jquery.sap.registermodulepath()?
here current source code of sap.ui.localresources does:
sap.ui.localresources = function(snamespace) { jquery.sap.registermodulepath(snamespace, "./" + snamespace.replace(/\./g, "/")); };
that's it. calls jquery.sap.registermodulepath
right away dots in namespace (if any) replaced "/"
.
- we can't pass user-defined url prefix
- the namespace tightly coupled actual folder hierarchy , name.
- sap discourages usage of api (for non-stand-alone apps).
- the api reference mentions api become obsolete.
to honest, don't know when i'd favor sap.ui.localresources
on resourceroots
.
feel free leave comment if not clear or if has example sap.ui.localresources
.
Comments
Post a Comment