zk页面每行数据的选中与取消选中
2016-06-29 16:40
211 查看
首先,上面这张图片页面每行数据的选中与取消选中以及全选的示例。全选包括所有行的数据,而不是本页的数据。好了,接下来看看代码是如何实现的吧。
一、页面代码(*.zul)
<cell>
<checkbox checked="@load(vm.getIntChecked(each.id))"
onCheck="@command('onCheckInt',nid=each.id,ischeck=self.checked,colName='id')" />
</cell>
checked的值为true或false,用于选中多选框。onCheckInt事件用于将colName='id'保存到后台list中便于后续操作。
二、后台代码
后台代码一般最好写在基类之中,避免子类重复冗余代码。
/**
* @category 多选按钮方法
* @param newsid 点击的id
* @param ischeck 选择/取消
* @param colName当newsid=-1时 为全选 全选当前basicList中的colName列添加checkedintids中
*/
@Command
@NotifyChange({ "basicList" })//通知basicList(查询的结果)
public void onCheckInt(@BindingParam("nid") Integer newsid,
@BindingParam("ischeck") boolean ischeck) {
if (ischeck) {
if (newsid != null){
if(newsid == -1 ){
//当为全选时,遍历整个basicList(查询的结果),将id存入checkedintids中
for(T gv: (ListModelList<T>) basicList.getInnerList())
checkedintids.add((Integer)gv.id());
}else
checkedintids.add(newsid);
}
} else {
if (newsid != null){
if(newsid == -1 ){
checkedintids.clear();
}else{
checkedintids.remove(newsid);
}
}
}
}
/**
* 用于回显已经选中的行
* @param checkid 每行数据的id值
* @return
*/
public boolean getIntChecked(Integer checkid) {
//当传进来的id在checkedintids里面存在时,表示已选中
return checkedintids.contains(checkid);
}
相关文章推荐
- dubbo使用简单说明
- windows下使用GIT
- 最近发现的开源项目
- 我的外包书签
- zookeeper集群搭建
- VIM设置代码折叠
- 动态规划之最长公共子序列
- 网易train
- zookeeper原理
- 支持李连杰的"壹基金"
- ZK for eclipse
- KAV7.0 key(更新日期08-04-29)
- Page is already covered by another Data Binder. Cannot be covered by this Data Binder again. Page:userGuide
- 时光悄悄流逝,光阴不再使你我天真
- 当今国内最领先的网络舆情监控系统为你揭开神秘的面纱
- 短线看盘
- ZooKeeper集群配置
- 自平方分形
- ZK 初用感受
- VIM 配置之代码折叠