easyui combobox实现下拉自动提示补全功能

<input id="cc" name="nickName" class="easyui-combobox" style="width:200px">
var find = function (param, success, error) {
        var q = param.q || "";
        if (q.length <= 0) {
            console.log("q.length <= 0");
            return false;
        }
        $.post("getNickName",{"nickName": q},function (data) {
            debugger
            var items = $.map(data, function(result,index){
                return {
                    value:index,
                    text:result
                }; //遍历数组中的值
            });
            /* var items = $.each(data, function(index,value){//第一个是下标,第二个是值
                return {
                    value:index,
                    text:value
                }; //遍历数组中的值
            }); */
            success(items);//调用loader的success方法,将items添加到下拉框中
        });
    }
    $('#cc').combobox({
        url : 'getNickName',
        valueField : 'value',
        textField : 'text',
        loader : find,
        mode : 'remote'
    });

上面代码中find方法是combobox的loader调用的方法

posted @ 2018-08-29 17:41  十黎九夏  阅读(1777)  评论(0编辑  收藏  举报