Fix list-component.js: Remove non-existent refresh() method and use proper subwidgets array management for bricks framework compatibility

This commit is contained in:
yumoqing 2026-04-22 17:07:42 +08:00
parent e726abcddb
commit 3182fcdf97

View File

@ -48,47 +48,39 @@ bricks.List = class extends bricks.VBox {
}
renderItems() {
// Clear existing children
// Clear existing children by resetting subwidgets array
this.subwidgets = [];
this.children.forEach(child => child.remove());
this.children = [];
// Render each item using urlwidget to load the item template
this.items.forEach((item, index) => {
const itemContainer = new bricks.VBox({
width: '100%',
height: this.itemHeight + 'px'
});
// Store item data on the container for reference
itemContainer._listItemData = item;
itemContainer._listItemIndex = index;
// Create urlwidget binding to load the item template
if (!itemContainer.binds) {
itemContainer.binds = [];
}
itemContainer.binds.push({
wid: 'self',
event: 'on_parent',
actiontype: 'urlwidget',
target: 'self',
// Create new item containers and add to subwidgets
this.subwidgets = this.items.map((item, index) => {
return {
widgettype: "VBox",
options: {
width: "100%",
height: this.itemHeight + "px"
},
_listItemData: item,
_listItemIndex: index,
binds: [{
wid: "self",
event: "on_parent",
actiontype: "urlwidget",
target: "self",
options: {
url: this.item_template_url,
params: {
item: item,
index: index,
id: 'item_' + index
id: "item_" + index
}
},
mode: 'replace'
mode: "replace"
}]
};
});
this.appendChild(itemContainer);
});
this.refresh();
// In bricks framework, updating subwidgets should automatically trigger re-render
// No need for explicit refresh or invalidate calls
}
// Public method to reload data