easyui combobox动态绑定数据

1.jsp上的写法

  <input class="easyui-combobox" id="first_catalogue"  style="width:30%;" value="--请选择所属分类--" >  

2.js

    $(function(){ 
     // $("#first_catalogue").parent(".l").show();     
   $('#first_catalogue').combobox({ 
    url:'<%=basePath%>getDic/getFirstCategory.do?userCategory=${pd.userCategory}',
    valueField:'id',
    textField:'text', 
    required: true,
    editable:false,           
        /*  onLoadSuccess: function () {  //加载完成后,设置选中第一项  
                    var val = $(this).combobox("getData");
                    //设置第一个值为选中值                 
                    $(this).combobox("select",val[0].text);  

                } , */
        onChange: function (){
        //getValue,getText分别获取value值,text
        var val =  $('#first_catalogue').combobox("getText");
        alert(val);    
        } 

        });
        //下方是在前端绑定数据
     /*  var data,json;
      data = [];
      data.push({ "text": "项目积累", "id":"xmjl" },{ "text": "最佳实践", "id":"xmjl" });
      $("#first_catalogue").combobox("loadData", data); */



}) 

3.Colltroller中的写法

    //获取所属分类的一级分类
    @RequestMapping(value="/getFirstCategory",produces="application/json;charset=utf-8")
    @ResponseBody
    //@ControllerInterceptor(Description="查询主题分类字典",Type=enumCtrlType.select)
    public JSONArray getFirstCategory()throws Exception{
        String returnCategory="";
        JSONArray JsonArray = new JSONArray();  
        PageData pd = this.getPageData();
        String userCategory = pd.getString("userCategory");
        List<String> firstCategory=ResoDictFacade.getFirstCategory(userCategory);
        for(int i=0;i<firstCategory.size();i++){
            String Category=firstCategory.get(i);
            /*Map params =  new HashMap();
                params.put("text", Category);
                params.put("id", "option_"+i);
           JSONArray array = JSONArray.fromObject(params);
           returnCategory+=array;*/
            JSONObject Json = new JSONObject();    
            //JSONObject对象中添加键值对
            Json.put("id", "option_"+i); 
            Json.put("text", Category);
            //将JSONObject对象添加到Json数组中 
            JsonArray.add(Json);

        }       
        return JsonArray;
    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值