From 2cda5570dc4847fa73b1804cad5a7fb034825323 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 22 Apr 2026 17:08:54 +0800 Subject: [PATCH] Fix list-component.js: Use correct bricks API methods - clear_widgets(), add_widget() instead of non-existent refresh() and appendChild() --- wwwroot/list-component.js | 63 ++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/wwwroot/list-component.js b/wwwroot/list-component.js index cf952f0..09eb3d8 100644 --- a/wwwroot/list-component.js +++ b/wwwroot/list-component.js @@ -48,39 +48,46 @@ bricks.List = class extends bricks.VBox { } renderItems() { - // Clear existing children by resetting subwidgets array - this.subwidgets = []; + // Clear existing children + this.clear_widgets(); - // Create new item containers and add to subwidgets - this.subwidgets = this.items.map((item, index) => { - return { - widgettype: "VBox", + // 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', options: { - width: "100%", - height: this.itemHeight + "px" + url: this.item_template_url, + params: { + item: item, + index: index, + id: 'item_' + index + } }, - _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 - } - }, - mode: "replace" - }] - }; + mode: 'replace' + }); + + // Use correct bricks API to add widget + this.add_widget(itemContainer); }); - // In bricks framework, updating subwidgets should automatically trigger re-render - // No need for explicit refresh or invalidate calls + // No need for refresh() call - add_widget should handle rendering } // Public method to reload data