首先extjs本身是有過濾能力的,默認會根據你錄入的內容過濾displayfield
而這有時候不足夠,比如不能模糊查詢,使用后臺過濾的話又比較卡體驗不好
下面有個簡單的前臺過濾方式
//combox的前臺模糊查詢過濾
function FilterCombox(e) {
var combo = e.combo;
if (!e.forceAll) {
var value = e.query.replace(/^\s*|\s*$/g, "").toUpperCase();
combo.store.filterBy(function (record, id) {
var text = record.get(combo.displayField).toUpperCase();
return (text.indexOf(value) != -1);
});
var field = combo.displayField;
combo.store.sort({
property: field,
direction: "ASC",
sorterFn: function (v1, v2) {
v1 = v1.get(field);
v2 = v2.get(field);
return v1.indexOf(value) > v2.indexOf(value) ? 1 : (v1.indexOf(value) < v2.indexOf(value) ? -1 : 0);
}
});
combo.expand();
return false;
}
}
其中前一部分用來過濾
后一部分用來進行相關性排序,確保內容里你輸入的內容出現得越早排得就越靠前
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/152757.html
標籤:JavaScript
上一篇:關于ie8的自適應問題
下一篇:css導航欄超鏈接居中樣式
