【问题标题】:Component reuse in manifest.json filemanifest.json 文件中的组件重用
【发布时间】:2017-09-21 12:20:14
【问题描述】:

我们目前正在构建一组应用程序,其中有很多重用。

目前我们通过使用 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>"
         }}

谁有一个可行的例子?

【问题讨论】:

    标签: sapui5


    【解决方案1】:

    这是一个包含嵌套组件的工作示例: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

    【讨论】:

    • 太棒了,它成功了!我很想摆脱 jquery.sap.registerModulePath,但我想我不能拥有它。
    • @JakobMariusKjær resourceRoots 还注册模块路径,如 here 解释的那样,如果这是您想要的。如果您想完全避免注册额外的命名空间,子组件必须知道其父组件的命名空间然而,由于紧密耦合,它违背了分离组件的目的。在我原来的example 中,子组件对父组件的命名空间一无所知(除了sap.ui5/routing/routes 中的可选parents)。
    猜你喜欢
    • 2013-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-28
    • 2021-02-21
    相关资源
    最近更新 更多