Fix list-component.js: Use correct bricks API methods - clear_widgets(), add_widget() instead of non-existent refresh() and appendChild()

This commit is contained in:
yumoqing 2026-04-22 17:08:54 +08:00
parent 3182fcdf97
commit 2cda5570dc

View File

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