错误“如果没有为控件定义默认聚合,则无法添加直接子项......"; [英] Error "Cannot add direct child without default aggregation defined for control ..."

查看:23
本文介绍了错误“如果没有为控件定义默认聚合,则无法添加直接子项......";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到错误如果没有为控件 sap.m.Label 定义默认聚合,则无法添加直接子项".不确定这是什么意思.这是我的片段:

I am getting the error "Cannot add direct child without default aggregation defined for control sap.m.Label". Not sure what this means. Here is my fragment:

<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core" xmlns:f="sap.f">
    <ResponsivePopover id="popover" title="{Name}" class="sapUiPopupWithPadding" placement="Bottom">
        <beginButton>
            <Button id="submit" text="{i18n>submit}" press="onSubmit" class="sapUiTinyMargin"/>
        </beginButton>
        <content>
            <f:GridContainer>
                <f:layout>
                    <f:GridContainerSettings rowSize="5rem" columnSize="8rem" gap="1rem"/>
                </f:layout>
                <f:layoutS>
                    <f:GridContainerSettings rowSize="5rem" columnSize="10rem" gap="0.5rem"/>
                </f:layoutS>
                <f:layoutXS>
                    <f:GridContainerSettings rowSize="5rem" columnSize="10rem" gap="0.5rem"/>
                </f:layoutXS>
                <Label text="{i18n>req}" required="true">
                    <f:layoutData>
                        <f:GridContainerItemLayoutData columns="3"/>
                    </f:layoutData>
                </Label>
                <Label id="txt" text="{i18n>cat}" required="true">
                    <f:layoutData>
                        <f:GridContainerItemLayoutData columns="3"/>
                    </f:layoutData>
                </Label>
                <RadioButton id="rbtn1" text="{i18n>grq}">
                    <f:layoutData>
                        <f:GridContainerItemLayoutData columns="4"/>
                    </f:layoutData>
                </RadioButton>
                <RadioButton id="rbtn2" text="{i18n>frq}">
                    <f:layoutData>
                        <f:GridContainerItemLayoutData columns="4"/>
                    </f:layoutData>
                </RadioButton>
                <TextArea id="txtarea" value="" placeholder="{i18n>typeq}" growing="true" growingMaxLines="10" width="100%">
                    <f:layoutData>
                        <f:GridContainerItemLayoutData columns="7"/>
                    </f:layoutData>
                </TextArea>
                <Text text="{i18n>note}">
                    <f:layoutData>
                        <f:GridContainerItemLayoutData columns="7"/>
                    </f:layoutData>
                </Text>
            </f:GridContainer>
        </content>
    </ResponsivePopover>
</core:FragmentDefinition>

预期结果是片段加载时不会出错.

Expected result is the fragment will load with out errors.

推荐答案

命名聚合必须与父级具有相同的命名空间.

The named aggregation must have the same namespace as the parent.

就您而言,问题出在 <SomeSapMControl><f:layoutData>.删除 中的 f: 使其与父级的命名空间匹配.

In your case, the issue is in < SomeSapMControl><f:layoutData>. Remove the f: in <f:layoutData> so it matches with parent's namespace.

sap.ui.require([
  "sap/ui/core/Core"
], Core => Core.attachInit(() => sap.ui.require([
  "sap/ui/core/Fragment"
], Fragment => Fragment.load({
  definition: `<f:GridContainer xmlns:f="sap.f" xmlns="sap.m">
    <Label text="Label within GridContainer">
      <layoutData>
        <f:GridContainerItemLayoutData columns="3"/>
      </layoutData>
    </Label>
  </f:GridContainer>`
}).then(control => control.placeAt("content")))));

<script id="sap-ui-bootstrap" src="https://ui5.sap.com/resources/sap-ui-core.js"
  data-sap-ui-libs="sap.m,sap.f,sap.ui.layout"
  data-sap-ui-theme="sap_fiori_3"
  data-sap-ui-async="true"
  data-sap-ui-compatversion="edge"
  data-sap-ui-xx-waitfortheme="init"
></script>
<body id="content" class="sapUiBody"></body>

如果没有为控件 sap.m.Label 定义默认聚合,则无法添加直接子项".不确定这是什么意思.

"Cannot add direct child without default aggregation defined for control sap.m.Label". Not sure what this means.

在控件定义中,控件开发人员可以分配默认聚合,以便应用程序开发人员可以添加子项,而无需在 XML 视图定义中显式放置聚合名称.这方面的一个例子是 sap.f.GridContainer.它的默认聚合是 items.src 因此,您不需要添加 <f:items> 来添加子项(请参阅我的上面的代码片段).

Within control definition, control developers can assign a default aggregation so that application developers can add children without having to put an aggregation name explicitly in the XML view definition. An example of this is sap.f.GridContainer. Its default aggregation is items.src Hence, you won't need to add <f:items> to add children there (See my code snippet above).

但是,如果控件没有默认聚合并且子节点名称与任何命名聚合都不匹配,则 XML 处理器将抛出上述错误.

If, however, the control has no default aggregation and the child node name matches with none of the named aggregations, the XML processor will throw the above error.

这篇关于错误“如果没有为控件定义默认聚合,则无法添加直接子项......";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆