首页 > 解决方案 > ZK 框架:使用 foreach 刷新动态布局

问题描述

我正在使用 forEach "myList" 来绘制元素。现在,当我更新“myList”中的数据时,我的页面无法重绘。
我尝试使用 invalidate() 但不行。
请帮我。
非常感谢。

我的代码如下:

<vlayout id="mainLayout" >
        <groupbox hflex="1" mold="3d" open="${forEachStatus.index==0}" forEach="${vm.myList}">
            <caption label="${each.groupName}" sclass="customIcon">
                <span id="arrow-${forEachStatus.index}" class="open-${forEachStatus.index}" />
            </caption>
            <vlayout hflex="1" spacing="10px">
                <groupbox hflex="1" mold="3d" forEach="${each.listData}" open="false">
                    <caption label="${each.groupName}" sclass="customIcon">
                    </caption>

                    <listbox emptyMessage="Empty data" mold="paging" pageSize="10"
                             sizedByContent="true" hflex="1">
                        <!--Listbox content here-->
                    </listbox>

                </groupbox>
            </vlayout>



        </groupbox>
    </vlayout>

视图模型

 @Command("onSearch")
@NotifyChange("myList")
public void onSearch() {
    try {
        //Business OK here, reload myList OK
        if(mainLayout!=null){
            mainLayout.invalidate();
        }
    } catch (Exception e) {
        mLogger.error(e.getMessage(), e);

    }

}

标签: jakarta-eeforeachzk

解决方案


如果没有看到完整的代码(或至少更多),很难提供帮助。看起来您正在使用 MVC 和 MVVM。我建议坚持使用 MVVM。具体来说,这可能很有用。

children在你中使用vlayout来迭代你的myList元素:

<vlayout children="@load(vm.myList)">
    <template name="children">
        <groupbox hflex="1" mold="3d" open="@load(each.index eq 0)">
            <!-- contents of groupbox here -->
        </groupbox>
    </template>
</vlayout>

在您的onSearch()方法中,您不需要 invalidate mainLayout@NotifyChange("myList")应该重新加载您的(myList假设您的 ViewModel 类中有一个 getter 方法)


推荐阅读