easyui combobox开启搜索自动完成功能
生活随笔
收集整理的這篇文章主要介紹了
easyui combobox开启搜索自动完成功能
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
combo.json
[{"id":-1,"text":" ","spell":""},{"id":1,"text":"類型1","spell":"lx1" },{"id":2,"text":"類型2","spell":"lx2" },{"id":3,"text":"類型3","spell":"lx3" },{"id":4,"text":"類型4","spell":"lx4" },{"id":5,"text":"類型5","spell":"lx5" }]?下面是代碼示例
<form><input type="text" id="combox1"> </form> /*** easyui combobox 開啟搜索功能,自動裝載選中的項目處理函數*/function onComboboxHidePanel() {var el = $(this);el.combobox('textbox').focus();// 檢查錄入內容是否在數據里var opts = el.combobox("options");var data = el.combobox("getData");var value = el.combobox("getValue");// 有高亮選中的項目, 則不進一步處理var panel = el.combobox("panel");var items = panel.find(".combobox-item-selected");if (items.length > 0) {var values = el.combobox("getValues");el.combobox("setValues", values);return;}var allowInput = opts.allowInput;if (allowInput) {var idx = data.length;data[idx] = [];data[idx][opts.textField] = value;data[idx][opts.valueField] = value;el.combobox("loadData", data);} else {// 不允許錄入任意項, 則清空el.combobox("clear");}}$("#combox1").combobox({required: true,editable: true,missingMessage: '請選擇裝載物料',valueField: "id",textField: "text",method: 'get',url: 'combo.json',mode: "local",onHidePanel: onComboboxHidePanel,filter: function (q, row) {//定義當'mode'設置為'local'時如何過濾本地數據,函數有2個參數://q:用戶輸入的文本。//row:列表行數據。//返回true的時候允許行顯示。//return row[$(this).combobox('options').textField].indexOf(q) > -1;return row["spell"].indexOf(q) >= 0;}});總結
以上是生活随笔為你收集整理的easyui combobox开启搜索自动完成功能的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 宁波车为什么这么便宜?
- 下一篇: 电动车没电能照样跑吗?