sapui5 – 在SAP Fiori中添加自定义库作为依赖项

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

SAP Fiori Launchpad for Developers – > Launchpad应用程序的最佳实践

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

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

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

与Fiori一样,您必须使用相对路径.

例如,为了我依赖工作,必须找到它

/resources/com/foo/library

将自定义库上载到ABAP SAPUI5存储库并使其具有相对路径的步骤有哪些?

编辑:

目前我在Component.init上加载了库

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

它工作,但我想将库设置为依赖

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的选项,所以我假设必须找到相对于资源的库

在您的Fiori App中:

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

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

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

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

现在您可以使用您的依赖项了.这就是为什么:

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.

Source: SAP UI5 API Documentation

相关文章

什么是设计模式一套被反复使用、多数人知晓的、经过分类编目...
单一职责原则定义(Single Responsibility Principle,SRP)...
动态代理和CGLib代理分不清吗,看看这篇文章,写的非常好,强...
适配器模式将一个类的接口转换成客户期望的另一个接口,使得...
策略模式定义了一系列算法族,并封装在类中,它们之间可以互...
设计模式讲的是如何编写可扩展、可维护、可读的高质量代码,...