Ext中的combobox有属性typeAhead:true 可以实现模糊匹配,但是是从开始匹配的,如果需要自定的的匹配,则需要监听beforequery方法,实现自己的匹配查询方法:
代码如下:
- var gfxmComb = new Ext.form.ComboBox({
- id : 'gfxmComb',
- store : gfxmStore,
- typeAhead : true,
- mode : 'local',
- editable : true,
- displayField :'xmMc',
- valueField :'xmBm',
- triggerAction : 'all',
- selectOnFocus : true,
- listeners : {
- 'beforequery':function(e){
-
- var combo = e.combo;
- if(!e.forceAll){
- var input = e.query;
-
- var regExp = new RegExp(".*" + input + ".*");
-
- combo.store.filterBy(function(record,id){
-
- var text = record.get(combo.displayField);
- return regExp.test(text);
- });
- combo.expand();
- return false;
- }
- }
- }
- });