【问题标题】:How to reuse a component from another application in UI5 1.38?如何在 UI5 1.38 中重用来自另一个应用程序的组件?
【发布时间】:2020-08-13 08:43:43
【问题描述】:

环境

框架:SAPUI5 V1.38.39
IDE:SAP WEB IDE

问题

我想在另一个应用程序中使用 SAPUI5 应用程序,为此我找到了以下资源:https://blogs.sap.com/2017/04/05/sapui5-how-to-reuse-parts-of-a-sapui5-application-in-othermultiple-sapui5-applications/

我想重用另一个应用的代码

在我使用的init中的component.js中:

var sPath = sHostUrl.includes("webidetesting") ? "https://gtyext.net" : sHostUrl;
jQuery.sap.registerModulePath("ztntapp", `${sPath}/sap/bc/ui5_ui5/sap/ztntapp/`);

在我看来:

<core:ComponentContainer 
    name="ztntapp" 
    manifestFirst="true" 
    component="ztntapp">
</core:ComponentContainer>

在 neo-app.json 中

{
    "path": "/sap/bc/ui5_ui5/sap/ztntapp/",
    "target": {
        "type": "destination",
        "name": "gtyext_net",
        "entryPath": "/sap/bc/ui5_ui5/sap/ztntapp/"
    },
    "description": "namespace.tntapp Resources"
}

来自重用应用的代码

在component.js中

sap.ui.define([
    "sap/ui/core/UIComponent",
    "sap/ui/Device",
    "./model/models"
], function (UIComponent, Device, models) {
    "use strict";

    return UIComponent.extend("TrackAndTrace.ztntapp.Component", {

        metadata: {
            manifest: "json"
        },
        init: function () {
        [...]
        },
        [...]
   });
});

在 neo-app.json 中(它是通过 SAP WebIDE 创建的默认文件):

{
  "welcomeFile": "/webapp/index.html",
  "routes": [
    {
      "path": "/resources",
      "target": {
        "type": "service",
        "name": "sapui5",
        "entryPath": "/resources",
        "version": "1.38.45"
      },
      "description": "SAPUI5 Resources"
    },
    {
      "path": "/test-resources",
      "target": {
        "type": "service",
        "name": "sapui5",
        "entryPath": "/test-resources",
        "version": "1.38.45"
      },
      "description": "SAPUI5 Resources"
    },
    {
      "path": "/webapp/resources",
      "target": {
        "type": "service",
        "name": "sapui5",
        "entryPath": "/resources",
        "version": "1.38.45"
      },
      "description": "SAPUI5 Resources"
    },
    {
      "path": "/webapp/test-resources",
      "target": {
        "type": "service",
        "name": "sapui5",
        "entryPath": "/test-resources",
        "version": "1.38.45"
      },
      "description": "SAPUI5 Test Resources"
    }
  ],
  "sendWelcomeFileRedirect": true
}

错误信息

未捕获的错误:无法从中加载“ztntapp/Component.js” https://webidetesting278-a392f.dispatcher.hana.ondemand.com/sap/bc/ui5_ui5/sap/ztntapp/Component.js: 错误:无法从中加载“TrackAndTrace/ztntapp/model/models.js” 资源/TrackAndTrace/ztntapp/model/models.js

neo-app.json 的点数:

其他研究

  • 用neo-app.json文件,问题是定位资源 从“ztntapp”,我看到还有一个 jQuery.sap.registerResourcePath 但我不知道如何使用它 本案

【问题讨论】:

  • 强烈建议升级UI5。对 1.38 的支持将在今年结束。只有这样,您才能使用当前接受的解决方案。

标签: sapui5 sap-fiori sap-cloud-platform sap-web-ide


【解决方案1】:

在您的第一个应用程序(主应用程序)中,请使用 manifest.json 添加组件用法,而不是 Component.js 中的jQuery.sap.registerModulePath

"componentUsages": {
    "ztntapp": {
            "name": " TrackAndTrace.ztntapp",
        "settings": {},
        "componentData": {},
        "lazy": true
    }
}

然后您需要调整您的主应用程序 neo-app.json 以启用 运行配置 以到达您的第二个应用程序(重用应用程序)

"routes": [
        {
      "path": "/webapp/resources/TrackAndTrace/ztntapp",
      "target": {
        "type": "application",
        "name": "ztntapp"
      }
    },
    {
      "path": "/resources/TrackAndTrace/ztntapp",
      "target": {
        "type": "application",
        "name": "ztntapp"
      }
    },

然后对于 resue 应用:部署您的应用,使其在 SAP WebIDE Fullstack 工作区中注册。

然后对于 WebIDE 中的主应用程序,选择 运行 > 运行配置 > 添加配置 > 作为 Web 应用程序运行 > 高级设置 标记 首先使用我的工作区 然后按 获取资源版本。在下面的列表中,您应该会在 Resources Name 下看到您的重用应用程序:

【讨论】:

  • 使用componentUsages 导航是一种全新的方法,在 1.38 中不可用。
【解决方案2】:

试试这个:

jQuery.sap.registerModulePath("ztntapp", "/sap/bc/ui5_ui5/sap/ztntapp")

而不是 jQuery.sap.registerModulePath("ztntapp", ${sPath}/sap/bc/ui5_ui5/sap/ztntapp/)

还请检查此链接: https://answers.sap.com/questions/668485/ui5-failed-to-load-componentjs-while-using-compone.html

【讨论】:

  • 感谢您的留言,我也试过了,我得到了同样的错误,它正确找到了component.js,但没有找到model.js,也没有找到manifest.json
猜你喜欢
  • 2020-03-03
  • 2019-07-10
  • 2019-12-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-23
  • 1970-01-01
相关资源
最近更新 更多