jakarta-ee - 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);
}
}
解决方案
如果没有看到完整的代码(或至少更多),很难提供帮助。看起来您正在使用 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 方法)
推荐阅读
- r - 如何在 Macbook 上的 QGIS 中集成 R?
- java - Java - 在字符串中的每个单词之前添加一个字符
- xamarin - 在 Xamarin 中选择集合视图项时如何禁用颜色
- jquery - Bootstrap nav-tabs 功能在 asp webform 情况下在 4.6 版本中不起作用
- google-cloud-platform - 我可以在一个谷歌云帐户下创建多个具有不同应用程序的公司吗?
- php - Wordpress 连接动态 php 页面
- cucumber - 用于并行测试的 QAF 奇怪行为
- python-3.x - 缩放后如何单击并按住并移动元素?
- amazon-web-services - 使用自定义云观察指标绘制每秒处理的消息数
- azure-devops - 如何使用 REST API 在 Azure DevOps 发布管道中添加任务