简体   繁体   English

如何在 sapui5 的数据绑定中嵌套两个数据模型

[英]How to nest two data models in a data binding in sapui5

I want to do something like the following in sapui5 , where two lists are nested , but the description is not showed, no matter what I change.我想在sapui5 中执行以下操作,其中嵌套了两个列表,但无论我如何更改,都不会显示描述。

Can anyone help?任何人都可以帮忙吗? Is it possible at all?有可能吗?

And what's more, I actually just want to add some text-controls or labels in the inner list (and I need something like a list with path or items to bind it), is there another possibility to do this instead of StandardListItem, so that it fits better to the upper part?更重要的是,我实际上只想在内部列表中添加一些文本控件或标签(并且我需要类似带有路径或项目的列表来绑定它),是否还有另一种可能来代替 StandardListItem,以便它更适合上半身吗?

    <List headerText="Events" items="{path: 'model1>/'}" >
       <items>
        <CustomListItem type="Navigation">
             <HBox>
                <VBox>
                    <Label text="{model1>message}"/>
                    <Text text="{model1>date}"></Text>
                    <Text text="{model1>time}"></Text>

                    <List id="MasterAttributeList" items="{ path: 'model2>/' }">
                            <items>
 critical part -->            <StandardListItem title="{model1>description}" 
                                           description="{model2>{= ${model1>key}}}"/>
                            </items>
                       </List>
                </VBox>
                 </HBox>
             </CustomListItem>
        </items>               
    </List>

Best regards!此致!

You cant bind they way you did, as it is a aggregation binding.你不能像你那样绑定它们,因为它是一个聚合绑定。 As per your XML view it is a nested list, it means that you need to have nested data to bind.根据您的 XML 视图,它是一个嵌套列表,这意味着您需要绑定嵌套数据。

For example: Nested Data例如:嵌套数据

{ 
  'items': [
    { 
        'message': "ss", 
        'date': "2020-12-12", 
        'time': "12:00",
        'items1': [
            { 'description': "description", 'key': "2141" },
            { 'description': "description", 'key': "2141" },
            { 'description': "description", 'key': "2141" }     
        ]

    }, 
    { 
        'message': "ss", 
        'date': "2020-12-12", 
        'time': "5:00",
        'items1': [
            { 'description': "description", 'key': "2141" },
            { 'description': "description", 'key': "2141" },
            { 'description': "description", 'key': "2141" }     
        ] 
    }, 
    { 
        'message': "fff", 
        'date': "2020-12-12", 
        'time': "8:00",
        'items1': [
            { 'description': "description", 'key': "2141" },
            { 'description': "description", 'key': "2141" },
            { 'description': "description", 'key': "2141" }     
        ]  
    }
  ] 
}

The above data works fine for the nested list and also need to mention the templateShareable: true property as well上述数据适用于嵌套列表,还需要提及templateShareable: true属性

<List headerText="Events" items="{path: '/items'}" >
    <items>
       <CustomListItem type="Navigation">
         <HBox>
            <VBox>
                <Label text="{message}"/>
                <Text text="{date}"></Text>
                <Text text="{time}"></Text>
                <List items="{path:'items1', templateShareable: true}">
                    <items>
                        <StandardListItem title="{description}" description="{key}"/>
                    </items>
                </List>
            </VBox>
        </HBox>
    </CustomListItem>
  </items>
</List>

Note: Use formatting as per your requirement.注意:根据您的要求使用格式。

I would suggest using a formatter.我建议使用格式化程序。

The function then might look like this:该函数可能如下所示:

formatDescription(oItem, sKey) {
    return oItem[sKey];
}

and your XML might look like this你的 XML 可能看起来像这样

    <StandardListItem 
        title="{model1>description}"
        description="{ 
            parts: [ 'model2>', 'model1>key' ], 
            formatter: '.formatter.formatDescription' 
        }"/>

Explanation: By using model2> as a part of your formatter, you are passing the complete object (and not just a single property) which is bound to the item to the formatter.说明:通过使用model2>作为格式化程序的一部分,您将绑定到项目的完整对象(而不仅仅是单个属性)传递给格式化程序。


For your second question, why don't you use another CustomListItem in your inner list which fits your needs?对于您的第二个问题,为什么不在您的内部列表中使用另一个符合您需求的CustomListItem

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM