sapui5 - 部署到 SAP Cloud Platform 时,有没有办法重用组件?
问题描述
我正在尝试通过使用 ComponentContainer 重用另一个应用程序,如本博客所示:https ://blogs.sap.com/2017/10/23/demystifying-the-art-of-component-reuse-in -sapui5/
我的应用程序正在通过 SAP Web IDE Full-Stack 开发,并正在部署到 SAP Cloud Platform。通过部署到 ABAP 存储库,我已经看到了这种工作的示例,但这不是我们想要做的。
到目前为止,我已经创建了一个子应用程序和一个父应用程序,并且我正在尝试使用 ComponentContainer 从父应用程序调用子应用程序。我已经部署了子应用程序,但我不确定如何从父应用程序引用此应用程序。
这是我的 ParentApp 视图:
<mvc:View controllerName="Parent.MyParentApp.controller.View1"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:mvc="sap.ui.core.mvc"
xmlns:core="sap.ui.core"
displayBlock="true" xmlns="sap.m">
<App id="idAppControl">
<pages>
<Page title="{i18n>title}">
<content>
<Text text="Hello"/>
<core:ComponentContainer width="100%"
name="MyChildApp"
component="MyChildApp"/>
</content>
</Page>
</pages>
</App>
ParentApp 组件.js
jQuery.sap.registerModulePath("MyChildApp", "/mychildapp/");
jQuery.sap.require("MyChildApp.Component");
ParentApp neo-app.json
{
"path": "/mychildapp/",
"target":{
"type": "application",
"name": "mychildapp"
},
"description": "My Child App"
}
这是我的 ChildApp 视图:
<mvc:View controllerName="Child.MyChildApp.controller.View1" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:mvc="sap.ui.core.mvc"
displayBlock="true" xmlns="sap.m">
<App id="idAppControl">
<pages>
<Page title="{i18n>title}">
<content>
<Text text="World"/>
</content>
</Page>
</pages>
</App>
目前我只是收到错误:“未捕获(承诺)错误:无法从../../resources/myChildApp/model/models.js加载'myChildApp/model/models.js':404 - ”。
我假设问题与 Component.js 和 neo-app.json 中给出的路径有关,但我不确定在云平台上工作时这些路径需要是什么。
我对 Ui5 开发还很陌生,所以不确定我想要做的事情是否可行,但是对此的任何建议/帮助将不胜感激。
谢谢
解决方案
肯定是因为走错了路。为了找到正确的路径,您可以执行以下操作:
1) 打开 chrome DevTools 并打开 Network 选项卡。
我的猜测是您的子应用程序的 Component.js 将显示为红色,这意味着它没有加载。如果将鼠标悬停在父应用程序的 Component.js 文件上,您将能够看到存储父应用程序的路径。希望如果您将此路径调整为类似路径,但对于您的子应用程序,您的重用将起作用。
我的猜测是您的父应用程序组件的路径看起来像“/sap/fiori/parentApp/Component.js”。
如果是这种情况,请在父应用程序的组件中尝试以下操作:
jQuery.sap.registerModulePath("MyChildApp", "/sap/fiori/mychildapp");
推荐阅读
- sql-server - SQL Server 在没有权限的情况下将页面锁定在内存中
- javascript - 如何在不更改键顺序的情况下根据属性值拆分数组?
- typescript - 打字稿构造函数中的“new()=>”
- matlab - 如何在绘图中的标签值及其表示值之间添加空格?
- html - 为什么当我想 ng build --prod 这个问题出现了?
- mysql - 节点js mysql错误意外输入结束
- python - 在 Python 3 的 pygame 模块中,是否可以绘制轮廓颜色与内部颜色不同的矩形?
- rx-java - RxJava 3.0.0 中不再使用 Disposables 了吗?
- python - 如何使用 Python 连接到 localhost python flask API
- kubernetes - 在sts中的环境变量中动态赋予.cluster.local DNS