在 SAP Fiori 中添加自定义库作为依赖项 [英] Adding a custom library as a dependency in SAP Fiori

查看:31
本文介绍了在 SAP Fiori 中添加自定义库作为依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义库 com.foo.library,我想将其包含为我构建的类似 Fiori 的应用程序的依赖项.

I have a custom library com.foo.library I would like to include as a dependency of a Fiori-like app I have built.

面向开发人员的 SAP Fiori Launchpad -> Launchpad 应用的最佳实践

SAP Fiori Launchpad for Developers -> Best Practices for Launchpad Apps

在component.js配置文件中声明配置信息,比如图标的位置,以及库依赖

Declare configuration information, like the location of icons, and library dependencies in the component.js configuration file

有道理,将我的库添加为依赖项看起来像

makes sense, adding my library as a dependency would look like

    dependencies: {
        libs: ["sap.m", "sap.ui.layout", "com.foo.library"],
        components: []
    },

对于 Fiori,您必须使用相对路径.

with Fiori you have the constraint that you must use relative paths.

例如,我的依赖项必须在

eg for my dependency to work it must be found at

/resources/com/foo/library

/resources/com/foo/library

将自定义库上传到 ABAP SAPUI5 存储库并为其提供相对路径的步骤是什么?

What are the steps for uploading a custom library into the ABAP SAPUI5 Repository and having it served with a relative path?

目前我使用 Component.init 加载了库

Currently i have the library loaded on Component.init using

 sap.ui.getCore().loadLibrary("com.foo.library", "absolute path to library");

它可以工作,但是我想将库设置为依赖项

it works, however I want to set the library as a dependency

ComponentMetadata.prototype._loadDependencies = function() {
..
            if (aLibraries) {
            jQuery.each(aLibraries, function(i, sLib) {
                jQuery.sap.log.info("Component \"" + that.getName() + 
                sap.ui.getCore().loadLibrary(sLib);
            });
        }

从上面的代码我可以看到,当组件加载库依赖项时,没有选项可以传入 url,所以我假设必须找到相对于资源的库

from code above I can see there is no option to pass in a url when the component loads the library dependencies, so i am assuming that the library has to be found relative to the resources

推荐答案

在您的 Fiori 应用程序中:

In your Fiori App:

  1. 将您的依赖项放入应用程序描述符 (manifest.json)(或者如果没有在 Component.js 中的配置中使用应用程序描述符)

  1. Put your dependencie into the app descriptor (manifest.json) (or if no app descriptor used into the config inside the Component.js)

dependencies: {
    libs: ["sap.m", "sap.ui.layout", "com.foo.library"],
    components: [com.foo.component]
}

  • 让 sap.ui.core 知道在哪里搜索你的库的命名空间.(你的 Component.js 的顶部)

  • Let sap.ui.core know where to search for the namespace of your library.(Top of your Component.js)

    jQuery.sap.registerModulePath("com.foo", "/Path/on/the/server/");
    

  • 现在您可以使用您的依赖项了.原因如下:

    And now you can use your dependencies. And here is why:

    在加载模块之前,其模块的最长注册前缀搜索名称并将关联的 URL 前缀用作前缀对于请求 URL.模块名称的其余部分附加到通过用斜杠 ('/') 替换点 ('.') 来获取请求 URL.

    Before a module is loaded, the longest registered prefix of its module name is searched for and the associated URL prefix is used as a prefix for the request URL. The remainder of the module name is attached to the request URL by replacing dots ('.') with slashes ('/').

    注册和搜索仅对全名段进行.

    The registration and search operates on full name segments only.

    来源:SAP UI5 API 文档

    这篇关于在 SAP Fiori 中添加自定义库作为依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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