关于排版的网站,传奇单职业手机版,西部数码网站管理助手 d盘,天猫seo搜索优化easyui的combobox根据后台数据实现自动输入提示功能发布时间#xff1a;2020-06-11 10:09:41来源#xff1a;51CTO阅读#xff1a;1981作者#xff1a;crackernetadauhuehkek最近做项目的时候遇到一个需求#xff0c;需要在录入数据的时候检索已经存在的数据记录#xff…easyui的combobox根据后台数据实现自动输入提示功能发布时间2020-06-11 10:09:41来源51CTO阅读1981作者crackernetadauhuehkek最近做项目的时候遇到一个需求需要在录入数据的时候检索已经存在的数据记录并从中提取相似的数据进行展示并选择以提高录入效率简单的说这个功能有点像在谷歌、百度搜索框里输入一个关键字然后自动在下边列举出与关键字相似的信息供选择。好啦现在功能说完了下边就直入正题把两种方法都列出来以供需要的人去选择使用其实两种方法的区别之处很小主要是在返回检索结果时调用方法不一样一种是map(),另一种是each(),这两个方法的区别我就不说了简单总结就是map()要从建数组each()直接返回原始数组基于这一点在内存开销上显然each()更好一点当然这个也不一概而论看各自需求了。服务端getAddress.aspdim myrs,sqlstr,singleJson,sqlstr2,qSet myrsserver.CreateObject(adodb.recordset)qReplace(Request.QueryString(q),,)qrequest.Item(param)set singleJson new MtRecToJsonsqlstr select address from callrecord where address like%q%sqlstr2select id,usr,uid,usrType,corp from usr order by idsqlstr3select top 1 * from usr where 12if q or qnull thenmyrs.Open sqlstr,Conn,1.1elsemyrs.Open sqlstr2,Conn,1.1end ifsingleJson.setRecordset(myrs)response.write singleJson.getListJsonDB()if not IsEmpty(myrs) thenif myrs.State0 thenmyrs.closeend ifset myrs nothingend ifconn.closeset conn nothing%TypeJson.aspJSON 接口通用类Class MtRecToJsonprivate recordsetprivate json_strprivate mask_fieldsprivate Sub Class_Initializeend subpublic property let setRecordset(byval rec) set recordset recend property设置值 参数为ADODB.recordset对象public sub setRecordset(rec)if TypeName(rec)Recordset thenset recordset recend ifend sub获得JSONpublic Function getOneJsonDB()dim ijson_str {if not IsEmpty(recordset) thenFor i0 To recordset.fields.count-1json_str json_str recordset.fields(i).namejson_str json_str :json_str json_str if not recordset.eof thenjson_str json_str recordset.fields(i).valueend ifjson_str json_str if ijson_str json_str ,end ifNextend ifjson_str json_str }getOneJsonDB json_strend function获得JSON 格式的listpublic Function getListJsonDB()dim i,kjson_str json_str [if not IsEmpty(recordset) thenFor k0 To recordset.recordcount-1if krecordset.pageSize then Exit forIf recordset.Eof Then Exit Forjson_str json_str {For i0 To recordset.fields.count-1json_str json_str recordset.fields(i).namejson_str json_str :json_str json_str if not recordset.eof thenjson_str json_str recordset.fields(i).valueend ifjson_str json_str if ijson_str json_str ,end ifNextjson_str json_str }if kjson_str json_str ,end ifrecordset.MoveNextnextend ifif(Right(json_str,1)Chr(44)) then查看拼接字符串最后是否有异常(偶尔存在逗号,不知道为什么),如果有就主动添加一个结尾字段json_str json_str end]elsejson_str json_str ]end ifgetListJsonDB json_strend functionend class%客户端show.asphtmlRemote JSONRemote JSONThis sample shows how to use JSON to retrieve data from a remote site.var myloader function(param, success, error) {var q param.q || ;if (q.length $.ajax({type: post,url: getAddress.asp,dataType: json,//contentType: application/x-www-form-urlencoded:charsetUTF-8,data: { param: q },success: function(data) {//alert(data);// var items $.map(data, function(value) {// return {// address: value// };// });var items $.each(data, function(value) {return this; //遍历数组中的值});success(items);//调用loader的success方法将items添加到下拉框中},error: function() {error.apply(this);}});}$(function() {$(#s1).combobox({loader: myloader,mode: remote,valueField: address,textField: address,editable:true,hasDownArrow: false});})