我对ZK完全陌生.我需要在zul文件中创建 N 个列表标题和 N 个列表单元.但是我不知道如何从Java控制器执行此操作,并且我不使用MVVM.
I am totally new in ZK. I need to create N listheaders and N listcells in my zul file. But I do not know how to do it from my java controller and I am not using MVVM.
问题可能是这样的:
@Wire private Window idWindow; private Listheader header; private Listcell item1; @Override public void onCreate(Event event) { header.setLabel("laaaa");// It would set just one header but I can have many (N headers) and same for items }<zk> <window id="idWindow" title="nameWindow" apply="controller.java" border="normal" closable="true" sizable="true" maximizable="true" maximized="true" height="85%" width="150%" style="overflow:auto;"> <!-- CONTINUES --> <listbox id="mainList" hflex="1" vflex="1"> <listhead> <listheader id="header" label="A" /> <listheader id="header1" label="B" /> <listheader id="header2" label="C" /> .... <listheader id="headerN" label="N" /> </listhead> <listitem> <listcell id="item1" label="A"/> <listcell id="item2" label="B"/> <listcell id="item3" label="C"/> .... <listcell id="itemN" label="D"/> </listitem> </listbox> <!-- CONTINUES --> </window> </zk>
推荐答案
您可以在zul中将listhead留空,将其连接到控制器中并在其中创建listheaders.重要的步骤是要求listbox提供其listhead,并将listheaders附加到其后.对于单元格,为您的listbox提供一个渲染器,如果您使用模型来提供列表数据,则该渲染器将为每个项目创建它们.
You can leave the listhead empty in the zul, wire it into your controller and create the listheaders there. The important step is to ask the listbox for its listhead, and append the listheaders to it. For the cells, give your listbox a renderer that creates them for each item if you use a model to give your list data.
您的祖尔会短很多:
<zk> <window ... > <listbox id="mainList" hflex="1" vflex="1"> <listhead /> </listbox> </window> </zk>然后在您的控制器中,在doAfterCompose中创建标题并附加渲染器:
Then in your controller, you create the header in doAfterCompose and attach the renderer:
@Wire private Listbox mainList; @Override // This method should be specified by a composer super class public void doAfterCompose(Component comp)throws Exception { super.doAfterCompose(comp); mainList.setModel(someModelWithYourData); // create listheaders (manually/in for-loop/based on data...) Listhead head = mainList.getListhead(); head.appendChild(new Listheader("A")); ... // attach renderer mainList.setItemRenderer(new ListitemRenderer<Object>() // use proper data type instead of Object { @Override public void render(Listitem item, Object data, int index) throws Exception { item.appendChild(new Listcell("a")); ... } }); }zk开发人员网站上还有一个示例: https ://www.zkoss/wiki/ZK_Developer%27s_Reference/MVC/View/Renderer/Listbox_Renderer
There is also an example on zk's developer sites: www.zkoss/wiki/ZK_Developer%27s_Reference/MVC/View/Renderer/Listbox_Renderer
如果无法使用模型,还可以将listitems附加到zul或控制器中,然后创建列表单元:
In case you cannot use a model, you could also append the listitems in the zul or in the controller, and then create the listcells:
for (Component child : mainList.getChildren()) { if (child instanceof Listitem) { Listitem item = (Listitem) child; // do the same as in the renderer } }更多推荐
如何在ZK中动态添加列表标题和列表单元格
发布评论