何时使用 jQuery.sap.registerModulePath() 举例? [英] When to use jQuery.sap.registerModulePath() with an example?

查看:26
本文介绍了何时使用 jQuery.sap.registerModulePath() 举例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已尝试阅读上述 SAPUI5 文档,但我无法清楚地理解其用法.还有 sap.ui.localResources()jQuery.sap.registerModulePath() 之间有什么区别以及什么时候使用什么?

如果有人能用一个简单的例子来解释,那将非常有帮助.也可以使用jQuery.sap.registerModulePath()来加载mockData吗?

解决方案

如果您在 bootstrap 配置 或在 引导配置>应用程序描述符,您一直在使用jQuery.sap.registerModulePath,因为 resourceRoots 中定义的每个键值对都作为参数传递给该静态方法.

例如,您的 index.html 中可能有这样的内容:

<script id="sap-ui-bootstrap" src="..."data-sap-ui-resourceroots='{"my.app": "./"}'...></脚本>

UI5 然后全局注册 namespace ("my.app") 作为参考说每当在解析其他模块名称时提到该名称,我应该寻找注册路径"中的目标模块,在我们的例子中,它是相对于当前document.location.href"./".>

上面的代码和直接调用jQuery.sap.registerModulePath("my.app", "./")[1]是一样的.

  • 在这里,我们可以传递用户定义的 URL 前缀.例如: "../" 而不是 "./" 如果项目在 更深一层,例如mockserver.html
  • 如果我们有一个更深层次的模块,例如在custom/control/somewhere/c3/chart/中,我们可以注册另一个命名空间:"my.app.c3chart": "./custom/control/somewhere/c3/chart" 然后
    • 例如在 XMLView 定义中将其用作快捷方式:
      xmlns:c3="my.app.c3chart" 而不是xmlns:c3="my.app.custom.control.somewhere.c3.chart".
    • 通过在模块文件更改其层次结构级别时仅更改注册路径来降低维护成本.命名空间 "my.app.c3chart" 仍然可以在任何地方使用.

[1]:从 1.58 开始,不推荐使用 API.手动注册命名空间时,API sap.ui.loader.config 应该使用:

sap.ui.loader.config({路径:{"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,并将命名空间中的点(如果有)替换为 "/".

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.

  • Here, we can pass user-defined URL prefix. E.g.: "../" instead of "./" which is needed if the project has another *.html file in one hierarchy level deeper such as mockserver.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
    • Use it as a shortcut for example in the XMLView definition:
      xmlns:c3="my.app.c3chart" instead of xmlns:c3="my.app.custom.control.somewhere.c3.chart".
    • Reduce maintenance costs by changing only the registered path when the module file changes its hierarchy level. The namespace "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 "/".

  • We can't pass any user-defined URL prefix
  • The namespace is tightly coupled with the actual folder hierarchy and name.
  • SAP discourages the usage of this API (for non-stand-alone apps).
  • The API reference mentions that this API will become obsolete. is deprecated

这篇关于何时使用 jQuery.sap.registerModulePath() 举例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆