首页 > 解决方案 > Error: "Cannot add direct child without default aggregation defined for control XYZ"

问题描述

I tried to find a solution by checking other questions with a similar error but none could help me. I tried to run the Component.js from my app in sandbox. Running the index.html works fine. My starting view is this:

<mvc:View
  xmlns="sap.m"
  xmlns:mvc="sap.ui.core.mvc"
  controllerName="com.sap.build.standard.qrCodeScanner.controller.Home"
>
  <Page id="home"
    class="customHomeBackground"
    showHeader="true"
    title="Home"
    showFooter="true"
  >
    <content>
      <FlexBox
        class="customFlexBoxHome"
        justifyContent="Center"
        alignItems="Center"
        wrap="Wrap"
      >
        <GenericTile class="customTile"
          header="Scan invitations"
          subheader="from your customers"
          frameType="OneByOne"
          press="_onGenericTilePress1"
        >
          <TileContent>
            <ImageContent src="sap-icon://bar-code"/>
          </TileContent>
        </GenericTile>
      </FlexBox>
    </content>
    <footer/>
    <headerContent/>
    <subHeader/>
    <customHeader/>
  </Page>
</mvc:View>

It's simply a single GenericTile. I can't access this view because of

Error: Cannot add direct child without default aggregation defined for control sap.m.GenericTile

console error

Accessing the other views is no problem. So when I add e.g. a button instead of the GernericTile + children, it works fine.

I also tried to add one of these sample tiles instead but same error. What's the problem with the GenericTile?

标签: sapui5

解决方案


捎带@sunil-bn的回答

根据提供的plunkr Sunil ,在当前版本的 UI5 中,示例代码可以正常工作。

但是,如果您像这样将库版本更改为 1.38.15 ,则会根据 OP 的问题将其损坏。

看看区别。在最新版本中,此代码有效:

<GenericTile>
    <TileContent>
        <ImageContent src=""/>
    </TileContent>
</GenericTile>

但在旧版本中,需要相应地显式添加命名聚合:

<GenericTile>
    <tileContent> <!-- named aggregation required. Default since 1.46.x -->
        <TileContent>
            <content> <!-- named aggregation required. Default since 1.38.18 -->
                <ImageContent src=""/>
            </content>
        </TileContent>
    </tileContent>
</GenericTile>

你需要弄清楚你使用的是什么版本的 UI5 并使用适当的 SDK 文档来构建你的应用程序,否则你会遇到麻烦。

您可以通过在 URL 中添加版本号来查看特定版本的 Demo Kit,例如https://ui5.sap.com/1.38.8/


推荐阅读