zk listbox 级联查询

因需要写一个两级联动的listbox。没有用spring 和hibernate,也没有用数据绑定。只是最简单的在<zscript>脚本里写程序。
<label value="国家:" /> <listbox id="countryy" mold="select" onCreate="self.setSelectedIndex(0)"onSelect="change()" >
<listitem forEach="${country}" label="${each.name}" value="${each.id}" />
[img]http://dl.iteye.com/upload/attachment/405887/7a20ac60-cc71-34b7-954c-537c5adab263.jpg[/img]
</listbox >
用onselect 监听被选中国家。
<label value="地区:" />
<listbox id="arear" mold="select" fulfill="countryy.onSelect" onSelect="getAgen()"onCreate="self.setSelectedIndex(0)"></listbox<label value="经销商:" /><listbox id="agentt" mold="select" fulfill="arear.onSelect"></listbox>
根据国家id查询对应的地区,根据地区id和国家id,查询出经销商。
<zscript><![CDATA[

import bean.Area;
import bean.Agent;
void change()throws Exception{
Listitem lt=countryy.getSelectedItem();
String id=lt.getValue().toString();
List area=se.getArea(id);


if(arear.getItems()!=null){
arear.getItems().clear();}
for(int i=0;i<area.size();i++){
Listitem li=new Listitem();
li.setLabel(((Area)area.get(i)).getName());
li.setValue(((Area)area.get(i)).getArea_id());
li.setParent(arear);
}

}
void getAgen()throws Exception{
Listitem li=countryy.getSelectedItem();
String cid=li.getValue().toString();

Listitem ll=arear.getSelectedItem();
String aid=ll.getValue().toString();
List agent=se.getAgent(cid,aid);

agentt.getItems().clear();
for(int i=0;i<agent.size();i++){
Listitem lc=new Listitem();
lc.setLabel(((Agent)agent.get(i)).getName());
lc.setValue(((Agent)agent.get(i)).getAgent_id());
lc.setParent(agentt);
}
}

]]>
</zscript>
对于zk的异步交互理解较差,所以用了最简单的清除组件,添加组件。希望对其他和我一样的新手有帮助吧。O(∩_∩)O~共勉。
还有一点小小的bug就是当地区默认第一项时,经销商是不会出来的。解决方法,不过有朋友说在显示二级联动列表的时候传个默认的一级列表的id。对 就是还用添加组件的方法:
<zscript><![CDATA[ //default area
import bean.Area;
String country_id=countryy.getItemAtIndex(0).getValue().toString();
List area=se.getArea(country_id);
for(int i=0;i<area.size();i++){
Listitem li=new Listitem();
li.setLabel(((Area)area.get(i)).getName());
li.setValue(((Area)area.get(i)).getArea_id());
li.setParent(arear);
}
]]>
</zscript>
<zscript><![CDATA[//default agent
import bean.Agent;
String area_id=arear.getItemAtIndex(0).getValue().toString();
List agent=se.getAgent(country_id,area_id);
for(int i=0;i<agent.size();i++){//add items
Listitem lc=new Listitem();
lc.setLabel(((Agent)agent.get(i)).getName());
lc.setValue(((Agent)agent.get(i)).getAgent_id());
lc.setParent(agentt);
}
]]></zscript>

但是这样加载较慢,使用数据绑定可以实现,需要使用事件监听。有实现的朋友可以相互讨论下。邮箱hong13626@foxmail.com
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值