combobox的联动练习

  老师的项目中,网站右上有四个联动的combobox,今天第一次尝试解决。外观如图:

  首先第一次登陆系统时,需要分别载入4个框中的数据。通过easyui-combobox的url

属性请求php返回json数据即可,json中的value是名称,id是编号。

  然后当选择省时。触发combobox的onSelect事件,先将它clear,然后用JS改变后面

下拉框的url即可联动。

  url中要包含现在的动作信息,和选择下拉框项的id值(编号),id值通过selection对象

的id属性获得。

//当选择省份时
    $('#provinceSelectID').combobox({
        onSelect:function(selection){
            //获取公司下拉框
            var com=$('#companySelectID');
            
            com.combobox('clear');
            com.combobox({
                //更改url
                url:"$webdb[www_url]/do/index.php?action=proCom&proID="+selection.id,
                valueField:'id',
                textField:'text'
            });
            var con=$('#controlSelectID');
            //控制中心的联动
            con.combobox('clear');
            con.combobox({
                //更改url
                url:"$webdb[www_url]/do/index.php?action=proCon&proID="+selection.id,
                valueField:'id',
                textField:'text'
            });
            //变电站的更改
            var sub=$('#substationSelectID');
            sub.combobox('clear');
            sub.combobox({
                //更改url
                url:"$webdb[www_url]/do/index.php?action=proSub&proID="+selection.id,
                valueField:'id',
                textField:'text'
            });
            
            
        }
    });

  在php端,通过获取的$action来判断需要的是什么数据,然后通过当前用户和选项编号来获取下级的信息。然后让id为编号,text为名称,编译成json 返回给前台。

 1 if($action=="proCom"){
 2         $query='select distinct view_select.comid,COMPANYNAME FROM view_select where userid=\''.$userid.'\' and view_select.proid=\''.$proID.'\'';
 3         $results=$db->get_results($query,ARRAY_N);
 4         if(!$results){
 5             return null;
 6         }
 7         foreach ($results as $result){
 8             $item=array('id'=>$result[0],'text'=>$result[1]);
 9             array_push($items, $item);
10         }
11         $jsItems=json_encode($items);
12         echo $jsItems;
13     }

 

posted on 2013-03-05 17:14  XHuangX  阅读(567)  评论(0编辑  收藏  举报