【问题标题】:Update "Simple" Listbox ZK更新“简单”列表框 ZK
【发布时间】:2012-06-12 15:21:53
【问题描述】:

我想在单击提交按钮时更新列表框。列表框最初由 JSONObject 列表组成,单击提交按钮后,列表元素发生更改,列表框应随更改而更新,但我不能这样做。你能帮我更新列表框吗?

这就是我将 JSONObject 列表放入列表框中的方式

<listbox id="userListbox">
<listhead>
    <listheader label="Id"></listheader>
    <listheader label="Name"></listheader>
    <listheader label="Address"></listheader>
    <listheader label="Phone"></listheader>
</listhead>
<listitem forEach="${userController.list}">
    <listcell label="${each.id}" ></listcell>
    <listcell label="${each.name}" ></listcell>
    <listcell label="${each.address}" ></listcell>
    <listcell label="${each.phone}" ></listcell>
</listitem>

在用户控制器类中:

private List<JSONObject> list;

@Listen("onClick = #submitButton")
public void onSubmit(Event event) {
    loadUser();
}

private void loadUser() {
    JSONObject input = new JSONObject();
    input.put("name", nameBox.getText());

    list = getUserList(input);
}

public List<JSONObject> getList() {
    return list;
}

public void setList(List<JSONObject> list) {
    this.list = list;
}

我不知道如何更新列表框?谢谢你的帮助。

【问题讨论】:

    标签: listbox zk


    【解决方案1】:

    在 UserController 类中:

    private List<JSONObject> list;
    Listbox userListbox;
    @Listen("onClick = #submitButton")
    public void onSubmit(Event event) {
        loadUser();
    }
    
    private void loadUser() {
        JSONObject input = new JSONObject();
        input.put("name", nameBox.getText());
    
        list = getUserList(input);
        userListbox.setModel(list);
        userListbox.set//Your own item renderer
    }
    
    public List<JSONObject> getList() {
        return list;
    }
    
    public void setList(List<JSONObject> list) {
        this.list = list;
    }
    

    我不知道如何更新列表框?谢谢你的帮助。

    【讨论】:

    • 感谢您的帮助。因为我是 ZK 的新手,我应该创建类渲染器吗?在第一个代码(.zul 文件)中,我只是放置列表并调用 JSONObject 中的每个键,而不使用任何渲染器。我必须创建类渲染器来更新列表框吗?
    • 是的,您应该创建一个实现 ListitemRenderer 并覆盖方法 getListitem() 的 Renderer 类,下次当您的列表(数据)更改时,您只需执行一次 listbox.setModel() .
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-07
    • 1970-01-01
    • 2013-03-10
    • 1970-01-01
    • 2012-07-15
    相关资源
    最近更新 更多