我想在 sapui5 中做类似的事情,其中嵌套了两个列表,但无论我更改什么,都不会显示描述。
谁能帮忙?可能吗?
更重要的是,我实际上只想在内部列表中添加一些文本控件或标签(我需要类似带有路径或项的列表来绑定它(,是否有另一种可能性来代替 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>
此致敬意!
您不能像以前那样绑定它们,因为它是聚合绑定。根据您的XML视图,它是一个嵌套列表,这意味着您需要具有要绑定的嵌套数据。
例如:嵌套数据
{
'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" }
]
}
]
}
上面的数据适用于嵌套列表,还需要提及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>
注意:根据您的要求使用格式。
我建议使用格式化程序。
然后,该函数可能如下所示:
formatDescription(oItem, sKey) {
return oItem[sKey];
}
您的 XML 可能如下所示
<StandardListItem
title="{model1>description}"
description="{
parts: [ 'model2>', 'model1>key' ],
formatter: '.formatter.formatDescription'
}"/>
说明: 通过使用 model2>
作为格式化程序的一部分,将绑定到项的完整对象(而不仅仅是单个属性(传递给格式化程序。
对于你的第二个问题,你为什么不在你内心的列表中使用另一个符合你需求的CustomListItem
?