如何在ui5中为列表设置包含多个项目的模板
How to setup a template with multiple items for a list in ui5
在我的 UI5 应用程序中,有一个列表,我想在其中显示多个 DisplayListItem。因此,我为列表设置了一个模板以与
绑定
oList.bindAggregation("items", "/my_path", oListTemplate);
如果我这样构建模板:
oListTemplate = new sap.m.DisplayListItem(...);
一切都完美无缺。
但是现在我需要将几个 new sap.m.DisplayListItem(...)
和 oListTempate = [new sap.m.DisplayListItem(...), new sap.m.DisplayListItem(...),..];
之类的数组放入一个模板中。如果我这样做,我会因为没有给出模板而收到错误消息:
Error: Missing template or factory function for aggregation items
是否不能使用模板提供超过一项。在 sap 文档中:https://sapui5.hana.ondemand.com/1.34.9/docs/guide/91f057786f4d1014b6dd926db0e91070.html 有一行:
A template is not necessarily a single control as shown in the example above, but can also be a tree of controls.
正因为如此,我觉得是可以的,但是不知道怎么做。
提前谢谢你
遍历结果并为每个结果添加一个 DisplayListItem:
var aItems = [];
oResponse.results.forEach(function(oResult){
aItems.push(new sap.m.DisplayListItem({
label: "oResult.name"
})
);
});
将您的数组添加到列表中:
var oList = new sap.m.List({
headerText: "Test list",
items: aItems
});
指定模板的正确方法是这样的:
oList.bindAggregation("items", {
path: "/my_path",
template: oListTemplate
});
通过创建单个项目将项目添加到列表可能会导致性能问题。
在我的 UI5 应用程序中,有一个列表,我想在其中显示多个 DisplayListItem。因此,我为列表设置了一个模板以与
绑定
oList.bindAggregation("items", "/my_path", oListTemplate);
如果我这样构建模板:
oListTemplate = new sap.m.DisplayListItem(...);
一切都完美无缺。
但是现在我需要将几个 new sap.m.DisplayListItem(...)
和 oListTempate = [new sap.m.DisplayListItem(...), new sap.m.DisplayListItem(...),..];
之类的数组放入一个模板中。如果我这样做,我会因为没有给出模板而收到错误消息:
Error: Missing template or factory function for aggregation items
是否不能使用模板提供超过一项。在 sap 文档中:https://sapui5.hana.ondemand.com/1.34.9/docs/guide/91f057786f4d1014b6dd926db0e91070.html 有一行:
A template is not necessarily a single control as shown in the example above, but can also be a tree of controls.
正因为如此,我觉得是可以的,但是不知道怎么做。
提前谢谢你
遍历结果并为每个结果添加一个 DisplayListItem:
var aItems = [];
oResponse.results.forEach(function(oResult){
aItems.push(new sap.m.DisplayListItem({
label: "oResult.name"
})
);
});
将您的数组添加到列表中:
var oList = new sap.m.List({
headerText: "Test list",
items: aItems
});
指定模板的正确方法是这样的:
oList.bindAggregation("items", {
path: "/my_path",
template: oListTemplate
});
通过创建单个项目将项目添加到列表可能会导致性能问题。