错误:“如果没有为控件 XYZ 定义默认聚合,则无法添加直接子项”

C. *_*cah 4 sapui5

我试图通过检查具有类似错误的其他问题来找到解决方案,但没有一个可以帮助我。我试图在沙箱中从我的应用程序运行Component.js。运行index.html工作正常。我的起始观点是这样的:

<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>
Run Code Online (Sandbox Code Playgroud)

它只是一个单一的GenericTile. 我无法访问此视图,因为

错误:如果没有为控件 sap.m.GenericTile 定义默认聚合,则无法添加直接子项

控制台错误

访问其他视图没有问题。因此,当我添加例如按钮而不是GernericTile+ 子项时,它工作正常。

我还尝试添加这些示例图块之一,但是同样的错误。有什么问题GenericTile

Jor*_*org 6

捎带@sunil-bn 的回答

在当前版本的 UI5 中,示例代码运行良好,根据plunkr Sunil 提供。

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

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

<GenericTile>
    <TileContent>
        <ImageContent src=""/>
    </TileContent>
</GenericTile>
Run Code Online (Sandbox Code Playgroud)

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

<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>
Run Code Online (Sandbox Code Playgroud)

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

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