如果您正在使用resourceRoots
要么在引导配置或在应用程序描述符,您一直在使用jQuery.sap.registerModulePath始终作为每个键值对,定义在resourceRoots
,作为参数传递给该静态方法。
例如,您的index.html 中可能有这样的内容:
<script id="sap-ui-bootstrap" src="..."
data-sap-ui-resourceroots='{"my.app": "./"}'
...
></script>
UI5 然后注册名称空间 ("my.app"
)全局作为参考说“每当在解析其他模块名称时提到该名称时,我应该在注册路径“ 这是"./"
相对于当前document.location.href
在我们的例子中。
The above code is the same as calling jQuery.sap.registerModulePath("my.app", "./")
[1] directly.
- 在这里,我们可以传递用户定义的 URL 前缀。例如。:
"../"
代替"./"
如果项目中有另一个 *.html 文件,则需要该文件更深一层的层次结构,例如模拟服务器.html
- If we've a module in a deeper hierarchy, e.g. in
custom/control/somewhere/c3/chart/
, we can register another namespace: "my.app.c3chart": "./custom/control/somewhere/c3/chart"
and then
- 将其用作 XMLView 定义中的快捷方式:
xmlns:c3="my.app.c3chart"
代替xmlns:c3="my.app.custom.control.somewhere.c3.chart"
.
- 当模块文件更改其层次结构级别时,仅更改注册路径,从而降低维护成本。命名空间
"my.app.c3chart"
仍然可以在任何地方使用。
[1]:自 1.58 起,该 API 已弃用。手动注册命名空间时,APIsap.ui.loader.config应该使用:
sap.ui.loader.config({
paths: {
"my/anotherApp": "https://example.com/somePath/anotherApp"
}
});
sap.ui.localResources() 和 jQuery.sap.registerModulePath() 有什么区别?
这是当前的源代码什么的sap.ui.localResources实际上是:
sap.ui.localResources = function(sNamespace) {
jQuery.sap.registerModulePath(sNamespace, "./" + sNamespace.replace(/\./g, "/"));
};
就是这样。它调用jQuery.sap.registerModulePath
立即将命名空间中的点(如果有)替换为"/"
.
- 我们无法传递任何用户定义的 URL 前缀
- 命名空间与实际的文件夹层次结构和名称紧密耦合。
-
SAP 不鼓励此 API 的使用(对于非独立应用程序)。
- The API reference mentions that this API
will become obsolete. is deprecated