easyui的combobox的自动填充方法

HTML代码:

<select id="LogType" name="LogType" class="easyui-combobox" style="width: 157px;" required="false"
        missingmessage="请选择" data-options="panelHeight:'auto',method: 'get',valueField: 'Title',textField:'Title',
    url: '/Sys/ashx/DicHandler.ashx?categoryId=41'"></select>

JS代码

$("#UserName").autocomplete("/BlueVacation/Controller/WorkLogHandler.ashx?op=autocomplete&fn=UserName",
  {
   minChars: 1, //在触发autoComplete前用户至少需要输入的字符数.Default: 1,如果设为0,在输入框内双击或者删除输入框内内容时显示列表
   //cacheLength: 1,   //缓存的长度.即对从数据库中取到的结果集要缓存多少条记录.设成1为不缓存.Default: 10
   //multiple: true,   //是否允许输入多个值即多次使用autoComplete以输入多个值. Default: false
   matchContains: false, //决定比较时是否要在字符串内部查看匹配,如ba是否与foo bar中的ba匹配.使用缓存时比较重要.不要和autofill混用.Default: false
   autoFill: false, //要不要在用户选择时自动将用户当前鼠标所在的值填入到input框. Default: false
   mustMatch: false, //如果设置为true,autoComplete只会允许匹配的结果出现在输入框,所有当用户输入的是非法字符时将会得不到下拉框.Default: false
   //delay: 100, //击键后激活autoComplete的延迟时间(单位毫秒).Default: 远程为400 本地10
   dataType: "json",
   parse: function (data) { //加入对返回的json对象进行解析函数,函数返回一个数组
    return $.map(data, function (row) {
     return {
      data: row, //通过此参数设置formatItem函数的return值
      value: row.name + " " + row.value, //等同于formatMatch函数中return的内容
      result: row.name //等同于formatResult函数中return的内容
     }
    });
   },
   formatItem: function (row, i, max) {
    return row.name;
   }
  }
    );

后台代码

string getAutoCompleteJson()
        {
            string keyvalue = Request["q"];//查询的字段
            string FieldName = Request["fn"];//查询的字段
            string[] res = bll.GetAutoCompletionList(FieldName, keyvalue, 20);            
            return BlueVacation.Common.Base.GetAutoCompleteJson(res);
        }

 

posted on 2015-02-13 11:57  波澜不惊super  阅读(1372)  评论(0编辑  收藏  举报

导航