在将网格中的数据重新加载到zkoss时,无法更改网格的ui

时间:2013-09-11 04:54:23

标签: mvvm zk zk-grid

我有一个日期框

<datebox id="infrom" style ="z-index: 100000;" format="yyyy-MM-dd" value ="@bind(vm.date)"
    onChange="@global-command('dataChanged', indate = infrom.value)" /> 

日期的默认值现在为-1 并有一个按钮搜索

<button id="searchButton" label="Search" image="/img/search.png"  onClick="@command('listCars', indate = infrom.value)"/>

并且网格将加载昨天的数据 当我选择另一天 grid将加载所选日期的数据 还有我的网格

<listbox id="carListbox" height="" emptyMessage="No data found in the result" model="@bind(vm.cars)" >

    <listhead>
        <listheader label="Date" />
        <listheader label="Actionid" />
        <listheader label="Num user" />
        <listheader label="Total action" />
    </listhead>
    <template name="model" >
        <listitem>
            <listcell label="@bind(each.date)"></listcell>
            <listcell label ="@bind(each.action)"></listcell>
            <listcell label="@bind(each.user)"></listcell>
            <listcell label="@bind(each.total)"></listcell>
        </listitem>
    </template>
</listbox>

并且有我的代码

private List<Car> cars;
public List<Car> getCars()
{

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar c = Calendar.getInstance();
    c.setTime(new Date()); // Now use today date.
    c.add(Calendar.DATE, -1); 
    String output = sdf.format(c.getTime());
    final StringBuilder builder = new StringBuilder("");
    for (final Action action : getActions()) {
        if (action.getChecked()) {
          builder.append(';');
            builder.append(action.getActionid());
        }
    }
    String lstAction = builder.toString(); 
    lstAction = lstAction.substring(1);
    String[] arrAction = lstAction.split(";");
    cars = carService.search(output, arrAction);

    return cars;
}

    @Command
@NotifyChange("cars")
public void listCars(@BindingParam("indate") Date indate){
SimpleDateFormat dt1 = new SimpleDateFormat("yyyy-MM-dd");
String date  = dt1.format(indate);
final StringBuilder builder = new StringBuilder("");
for (final Action action : actions) {
    if (action.getChecked()) {
      builder.append(';');
        builder.append(action.getActionid());
    }
}
String lstAction = builder.toString(); 
lstAction = lstAction.substring(1);
String[] arrAction = lstAction.split(";");
cars = carService.search(date, arrAction);
//return result;
//carListbox.setModel(new ListModelList<Car>(result));
}

但是当我选择另一天时,我无法重新加载网格 请给我任何方式来解决他们 谢谢所有

1 个答案:

答案 0 :(得分:0)

为什么绑定param以使用@BindingParam(“indate”)?

如果您将日期值与此绑定:

<datebox style ="z-index: 100000;" format="yyyy-MM-dd" value ="@bind(vm.date)"
onChange="@global-command('dataChanged', indate = infrom.value)" /> 

所以你可能不会使用

String date  = dt1.format(indate);
在listCars函数中

,而不是在其中使用@BindingParam。

相反,您需要声明

private Date date;

在viewmodel中,带有他的getter和setter。