combobox使用

来源:互联网 发布:python 玩蛇网 编辑:程序博客网 时间:2024/06/03 19:38

  利用select option方法展示的下拉选,里面的内容是在JSP文件里面写死的,如果想动态获取数据库里的数据放在下拉选里面要用到combobox。

combobox有get set方法:

获取值:$("#department").combobox('getText');        $("#department").combobox('getValue');赋值:  $("#department").combobox('setText',row.department);                   $("#department").combobox('setValue',row.deptid);         <tr>            <td>所属部门:</td>          <td>           <input class="easyui-combobox " id="department" name="department" />          </td>          </tr> 

  网上关于使用combobox的方式有多种,我使用的是:

function getText(){  $("#department").combobox({                       url:"suc/findAllDept",                     // 向服务器请求的模式                       method : "post",                     data: "jsonp",                    valueField: 'id',                      textField: 'department'               }); }
valueField里放的是部门ID,textField里放的是部门名称,在数据库里的具体表信息为:


  通过url的地址到控制器里找对应的方法:

  @RequestMapping("findAllDept")  @ResponseBody    public JSONArray findAllDept(HttpServletRequest req,HttpServletResponse res) throws IOException{     JSONArray jsonArray=new JSONArray() ;      List<Map<String, String>> lists=new ArrayList<Map<String, String>>();     lists=sysUserService.findAllDept();     //System.out.println(lists);     jsonArray =JSONArray.fromObject(lists);     // res.setContentType("text/html;charset=utf-8");     // PrintWriter pw = res.getWriter();     // pw.write(jsonArray.toString());     // pw.flush();     // System.out.println(jsonArray);     return jsonArray;  }


  SQL语句:

<select id="findAllDept" resultType="Map" >    select id,department from sys_dept</select>


  该方法将查找出的部门信息返回给前端。最终显示在网页上为:

  

假如想对其内容进行修改,例如:所属部门原来是“研发中心”,现在想改为“呼叫中心”



想达到上图展示的效果的话,需要先调用getText()方法,然后取出现在的部门信息放在"#department"内。

     getText();     $("#department").combobox('setText',row.department);                $("#department").combobox('setValue',row.deptid);


0 0