You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SAPUI5:如何将展开实体集数组显示为树的子节点

SAP UI5 Tree控件:将SalesOrderItem转为树子节点的正确配置

问题核心:Tree控件的子节点需通过自身items聚合绑定,而非把List嵌套在父节点内容里;arrayNames参数要配合子items绑定才能生效。原代码里把SalesOrderItem的List作为父TreeItem的内容展示,没有形成树层级,调整方式如下:

修改步骤:

  • 保留Tree根节点的绑定参数,确保expand: 'to_Item'和arrayNames: ['to_Item/results']正确配置
  • 移除父节点FlexBox里的List控件,在CustomTreeItem内部添加items聚合,绑定子节点路径to_Item/results
  • 为子节点定义对应的TreeItem模板(这里用CustomTreeItem来展示订单行项目的详细信息)

修改后完整代码:

<Tree
    id="Tree"
    items="{ 
        path: '/A_SalesOrder', 
        parameters: { 
            expand: 'to_Item', 
            arrayNames: ['to_Item/results'] 
        } 
    }"
>
    <CustomTreeItem id="SC_CustomeTreeItem1">
        <content>
            <FlexBox
                id="SC_FBT1"
                alignItems="Start"
                width="100%"
            >
                <items>
                    <Text
                        text="{SalesOrder}"
                        class="sapUiSmallMarginEnd"
                    />
                    <Text text="{SalesOrderDate}">
                        <layoutData>
                            <FlexItemData growFactor="1" />
                        </layoutData>
                    </Text>
                    <Text
                        text="{TotalNetAmount}"
                        class="sapUiSmallMarginEnd"
                    />
                </items>
            </FlexBox>
        </content>
        <!-- 子节点绑定:将to_Item/results作为树的子层级 -->
        <items>
            <CustomTreeItem>
                <content>
                    <ObjectListItem
                        title="{SalesOrderItemText}"
                        number="{
                            parts:[{path:'NetAmount'},{path:'CurrencyCode'}],
                            type: 'sap.ui.model.type.Currency',
                            formatOptions: {showMeasure: false}
                        }"
                        numberUnit="{TransactionCurrency}"
                    >
                        <ObjectAttribute
                            text="{Material}"
                        />
                        <ObjectAttribute
                            text="{PricingDate}"
                        />
                    </ObjectListItem>
                </content>
            </CustomTreeItem>
        </items>
    </CustomTreeItem>
</Tree>

关键说明:

  • arrayNames: ['to_Item/results']告诉Tree控件,to_Item/results是当前节点的子节点数组
  • 父CustomTreeItem的items聚合绑定子节点路径,这样Tree才能识别出层级关系,自动生成展开/折叠按钮
  • 子节点可以根据需求选择StandardTreeItem或CustomTreeItem,这里用ObjectListItem是为了保留原有的行项目展示样式

内容的提问来源于stack exchange,提问作者MarcL

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 04:46:24