您的位置:首页 > 其它

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);

     }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  zk