sapui5 - 在manifest.json文件中重用组件

标签 sapui5

我们目前正在构建一组可重复使用的应用程序。

目前我们通过使用它来工作 jQuery.sap.registerModulePath 和 jQuery.sap.require。 但根据 Using and Nesting Components您应该能够在manifest.json 文件中声明您的重用组件。

我查看了 SAPUI5 Developer Guide ,但无法真正使其发挥作用。据我所知,我需要添加以下内容:

"sap.App" :{
    "embeddedBy" : "../.."
},
"sap.ui5": {
    "componentUsages" :{
        "<string for my reuse component>" : {
            "name" : "<name of the component>"
        }
    "dependencies" :{
        "components" : {
            "<namespace of my component>"
         }}

有人有一个可行的例子吗?

最佳答案

这是一个包含嵌套组件的工作示例:https://embed.plnkr.co/e7KS48/

描述符属性componentUsages可用since 1.47.0 。定义后,UI5 负责解析组件及其模块路径 before rendering所属的 ComponentContainer。

需要 ComponentContainer,因为没有容器就无法将组件放入 UI 中。在上面的示例中,容器是在 Home.view.xml 中使用相应的 usage 属性以声明方式定义的。

<core:ComponentContainer id="containerForChildComponent"
  autoPrefixId="true"
  settings="{id: 'childComponent'}"
  usage="reuseAnotherComponent"
  manifest="true"
  height="100%"
  async="true"
/>
"sap.ui5": {
  "componentUsages": {
    "reuseAnotherComponent": {
      "name": "anotherComponent",
      "lazy": false
    }
  },
  "resourceRoots": {
    "anotherComponent": "./component_B"
  },
  // ...
}

如您所见,resourceRoots 也可以在描述符中定义,它可以指向其他组件/应用程序位置。


版本低于 1.47 的 UI5 应用示例: https://embed.plnkr.co/ytXZJ9

关于sapui5 - 在manifest.json文件中重用组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46343788/

相关文章:

sapui5 - 如何获取当前路线?

javascript - 在shell本身而不是sapui5的新窗口中打开http链接

sapui5 - 在带有后端 servlet 的 Openui5 中使用 sap.m.UploadCollection 上传文件不起作用

javascript - SAPUI5 表排序不起作用

odata - 如何获取已过滤的 OData 结果的计数?

javascript - 如何加载特定目录下的所有本地资源?

odata - sapui5表只显示相同的记录

javascript - OpenUI5 控件不可见

javascript - 通过Id获取sapui5元素Like

javascript - 在 SAPUI5 中,您可以通过单击按钮触发智能表事件吗?