<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調用的方法