直接上代碼
$("#combobox1").combobox({
valueField : "value",
textField : "text",
height : 32,
method : "get",
editable : true,
delay : 600, //最后一次輸入事件與執行搜索之間的延遲間隔(執行自動完成功能的延遲間隔)
keyHandler : {
query : function (value) {
if (value == '') {
$("#combobox1").combobox("clear");
return;
}
var opts = $("#combobox1").combobox('options');
var data = $("#combobox1").combobox("getData");
$.each(data, function (k, node) {
//如果開啟拼音搜索后台需要支持一個pinyin的字段。
//if (node[opts.textField].indexOf(value) >= 0 || node['pinyin'].indexOf(value.toLocaleLowerCase()) >= 0) {
if (node[opts.textField].indexOf(value) >= 0) {
//如果是單選就可以加上這句
$("#combobox1").combobox("clear");
$("#combobox1").combobox("select", node[opts.valueField]);
return false;
}
});
}
},
data : [{
"value" : "1001001",
"text" : "泗水縣"
}, {
"value" : "1001002",
"text" : "嘉祥縣"
}, {
"value" : "1001003",
"text" : "市中區"
}, {
"value" : "1001004",
"text" : "兗州市"
}, {
"value" : "1001005",
"text" : "金鄉縣"
}, {
"value" : "1001006",
"text" : "曲阜市"
}, {
"value" : "1001007",
"text" : "梁山縣"
}, {
"value" : "1001008",
"text" : "微山縣"
}, {
"value" : "1001009",
"text" : "市轄區"
}, {
"value" : "10010010",
"text" : "汶上縣"
}, {
"value" : "10010011",
"text" : "魚台縣"
}, {
"value" : "10010012",
"text" : "任城區"
}, {
"value" : "10010013",
"text" : "鄒城市"
}
]
});
技術交流QQ群:15129679
