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){
// 得到每个record的项目名称值
var text = record.get(combo.displayField);
return regExp.test(text);
});
combo.expand();
return false;
}
}
}
});

代码:

var employee_store = new Ext.data.Store({
proxy:new Ext.data.HttpProxy({url:"../Process/Form_cli_e.ashx"}),
reader: new Ext.data.JsonReader({
//remote:true,
totalProperty:'totalProperty',
root:'root',
id:'employee_store'
},[
{name: 'ry_name'},
{name: 'ry_gh'}
])
});
function cli_e(){
var cli_e_box = new Ext.form.ComboBox({
mode:'remote',
idname:'cli_E',
name:'cli_E',
displayField:'ry_name',
valueField:'ry_gh',
store:employee_store,
typeAhead:false,
triggerAction:'query'
});
return cli_e_box;
}

1.使用simplestore正常 
2.使用远程数据,设置triggerAction:'all',正常 
3.使用远程数据,设置triggerAction:'query',读不出数据 
4.使用远程数据,设置triggerAction:'query',在combobox中输入4个字符可加载到数据,但没有筛选功能

combo.js

Ext.ns('Example');

Example.comboConfig = {
xtype:'combo' // we need id to focus this field. See window::defaultButton
,id:'combo' // we want to submit id, not text
,valueField:'persID'
,hiddenName:'persID' // could be undefined as we use custom template
,displayField:'persLastName' // query all records on trigger click
,triggerAction:'all' // minimum characters to start the search
,minChars:2 // do not allow arbitrary values
,forceSelection:true // otherwise we will not receive key events
,enableKeyEvents:true // let's use paging combo
,pageSize:5 // make the drop down list resizable
,resizable:true // we need wider list for paging toolbar
,minListWidth:220 // force user to fill something
,allowBlank:false // store getting items from server
,store:new Ext.data.JsonStore({
id:'persID'
,root:'rows'
,totalProperty:'totalCount'
,fields:[
{name:'persID', type:'int'}
,{name:'persLastName', type:'string'}
,{name:'persFirstName', type:'string'}
]
,url:'process-request.php'
,baseParams:{
cmd:'getData'
,objName:'person2'
,fields:'["persLastName","persFirstName"]'
}
}) // concatenate last and first names
,tpl:'<tpl for="."><div class="x-combo-list-item">{persLastName}, {persFirstName}</div></tpl>' // listeners
,listeners:{
// sets raw value to concatenated last and first names
select:function(combo, record, index) {
this.setRawValue(record.get('persLastName') + ', ' + record.get('persFirstName'));
} // repair raw value after blur
,blur:function() {
var val = this.getRawValue();
this.setRawValue.defer(1, this, [val]);
} // set tooltip and validate
,render:function() {
this.el.set(
{qtip:'Type at least ' + this.minChars + ' characters to search in last name'}
);
this.validate();
} // requery if field is cleared by typing
,keypress:{buffer:100, fn:function() {
if(!this.getRawValue()) {
this.doQuery('', true);
}
}}
} // label
,fieldLabel:'Combo'
}; // main entry point
Ext.onReady(function() {
Ext.QuickTips.init(); // invalid markers to sides
Ext.form.Field.prototype.msgTarget = 'side'; // create and show window
var win = new Ext.Window({
id:'combo-win'
,title:Ext.fly('page-title').dom.innerHTML
,layout:'fit'
,width:300
,height:150
,closable:false
,border:false // let window code to focus the combo on show
,defaultButton:'combo'
,items:{
xtype:'form'
,frame:true
,defaults:{anchor:'-20'}
,items:[{
xtype:'textfield'
,fieldLabel:'Dummy Field'
}
,Example.comboConfig
]
}
}); win.show(); }); // eo onReady

combo.html:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="ext/resources/css/ext-all.css" />
<link id="theme" rel="stylesheet" type="text/css" href="css/empty.css" />
<link rel="stylesheet" type="text/css" href="css/icons.css" />
<link rel="stylesheet" type="text/css" href="css/formloadsubmit.css" />
<link rel="shortcut icon" href="img/extjs.ico" />
<script type="text/javascript" src="ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext/ext-all-debug.js"></script>
<script type="text/javascript" src="combo.js"></script>
<title id="page-title">Combo with Remote Store by Saki</title>
</head>
<body>
<div class="adsense" style="margin:4px">
<script type="text/javascript"><!--
google_ad_client = "pub-2768521146228687";
/* 728x90, for examples ifram */
google_ad_slot = "5477402227";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div> <!-- delete following line if you don not want stats included -->
<?if("examples.extjs.eu"===$_SERVER["SERVER_NAME"]){$page='combo';include("stats.php");}?>
</body>
</html>

Ext.form.ComboBox级联菜单(mode : 'local[remote]')

var dwStore = new Ext.data.JsonStore({
url:"bdzJbqk.html?m=loaddwdata",
root:"dwresults",
totalProperty:"dwtotalCount",
fields:["id","name"]
});
dwStore.load(); var bdzStore = new Ext.data.JsonStore({
url:"bdzJbqk.html?m=loadbdzdata",
root:"bdzresults",
totalProperty:"dwtotalCount",
fields:["id","name"]
});
var bdzcombo = new Ext.form.ComboBox({
id:'bdz',
width:60,
listWidth:58,
store: bdzStore,
value: "全部",
valueField :"id",
displayField: "name",
forceSelection: true,
editable: false,
triggerAction: 'all',
//mode : 'local',
allowBlank:true
}); var dwcombo = new Ext.form.ComboBox({
width:150,
id:'search',
store: dwStore,
value: '${cdssdw}',
valueField :"id",
displayField: "name",
forceSelection: true,
hiddenName:'test',
editable: false,
triggerAction: 'all',
allowBlank:true,
emptyText:'请选择',
fieldLabel: '多选下拉ComBo',
mode : 'remote',
listeners:{
select :function(dwcombo){
bdzStore.load({params:{cdssdw: dwcombo.getValue()}});
}
}
});

现在我需要在点击dwcombo 下拉框的时候出发bdzcombo 并给它加载数据

我只说我遇到的问题了,关于怎么加载的我就认为大家都会了

我遇到了这样一个问题,当我点击第一级菜单的时候,第二级菜单并没有加载数据

反复试了几次之后我发现,必须先激活第二级的菜单,再点击第一级菜单,这时才能给第二级菜单加载数据

那么第二级菜单真的在加载页面时没有自动激活吗

我去API里看了一下,ComboBox就没有激活自身的方法

细心的朋友会发现这样产生效果是第二级菜单下面事实上是有两个格子

我才意思到我忘记了一个重要的属性,就是“mode”

试了之后,果然解决了这个问题

我设置了mode:'local'

原来是这样的,当我们点击第一级菜单的时候,由于select事件,就已经加载了第二级菜单的数据

那么我们在点击第二级菜单的时候,还用不用去服务器端去数据呢?

当然不用了,因为数据已经取过来了

我们只需要在本地取就可以了

而mode默认的值为remote

Ext ComboBox 动态查询的更多相关文章

  1. 自己写的一个关于Linq to Entity 动态查询的例子

    这两天一直想写一个动态查询的方式,先是晚上查询了一下,发现大家写的差不多都是一样的[如:http://www.cnblogs.com/ASPNET2008/archive/2012/10/28/274 ...

  2. WINFORM 多条件动态查询 通用代码的设计与实现

    经常碰到多条件联合查询的问题,以前的习惯认为很简单总会从头开始设计布局代码,往往一个查询面要费上老半天的功夫,而效果也不咋地.     前段时间做了个相对通用的多条件动态查询面,复用起来还是挺方便的, ...

  3. 基于jpa的specification实现动态查询

    spring data jpa为我们实现简单的crud操作提供了极大的方便.但大部分情况下,系统中都存在大量的动态查询操作,这个时候就可以借助spring data jpa的 Specificatio ...

  4. Thinkphp查询 1.查询方式 2.表达式查询 3.快捷查询 4.区间查询 5.组合查询 6.统计查询 7.动态查询 8.SQL 查询

    1.使用字符串作为条件查询 $user = M('User'); var_dump($user->where('id=1 AND user="蜡笔小新"')->sele ...

  5. 【EasyUI】combotree和combobox模糊查询

    这里说的模糊查询指在输入框输入,然后自动在下拉框中显示匹配结果,类似Google搜索提示 EasyUI库已经实现了combobox的查询过滤功能,但只能从头匹配,原因是EasyUI库的代码限制: fi ...

  6. Winform如何实现ComboBox模糊查询

    最近朋友问了一个关于Winform实现ComboBox模糊查询的知识点,自己好久没有搞Winform了,就上手练了一下,废话不多说,进入正题. 前台设计: 前台就是一个简单的Form窗体+一个Comb ...

  7. Linq 动态查询排序

    Linq的排序一般是这样写的: query.OrderBy(x => x.Tel).Skip().Take(); 实际使用中排序字段可能是通过字符类型的参数来设置的,于是想这样实现: query ...

  8. ibatis动态查询条件

    ibatis的调试相对困难,出错的时候主要依据是log4生成的log文件和出错提示,这方面要能比较熟练的看懂. 下面这个配置基本上包含了最复杂的功能:分页\搜索\排序\缓存\传值Hash表\返回has ...

  9. Linq动态查询简易解决之道(原创)

    因为项目需要使用Linq来查询数据,但是在多条件查询时,需要使用一大堆if(...!=string.empty)等判断条件感觉不是很优雅.网上搜索以下,大概找到了两种办法,一种是老外写的一个类,感觉用 ...

随机推荐

  1. SQL语句资料

    --语 句 功 能  --数据操作  SELECT --从数据库表中检索数据行和列  INSERT --向数据库表添加新数据行  DELETE --从数据库表中删除数据行  UPDATE --更新数据 ...

  2. Linux学习笔记:pwd与dirs的区别

    在Linux中可以使用pwd和dirs进行当前目录查看,分别用于显示当前目录和显示完整目录记录.具体如下: 1.pwd 显示当前目录 2.dirs 显示目录堆叠中的记录 END 2018-08-21  ...

  3. ef查询mysql数据库数据支持DbFunctions函数

    1.缘由 快下班的时候,一同事说在写linq查询语句时where条件中写两时间相减大于某具体天数报错:后来仔细一问,经抽象简化,可以总结为下面的公式: a.当前时间 减去 某表时间字段 大于 某具体天 ...

  4. WordPress前台后台出现一片空白的原因以及解决办法

    WordPress前台后台出现空白的可能原因有以下: 这个问题,一般是在进行以下操作后出现的: 1.网站更换新主题2.网站安装或升级插件3.升级了Wordpress版本 其实问题的根源在于你的主题.插 ...

  5. EFK收集Kubernetes应用日志

    本节内容: EFK介绍 安装配置EFK 配置efk-rbac.yaml文件 配置 es-controller.yaml 配置 es-service.yaml 配置 fluentd-es-ds.yaml ...

  6. InterSystems Ensemble学习笔记(二) Ensemble创建镜像, 实现自动故障转移

    系列目录 InterSystems Ensemble学习笔记(一) Ensemble介绍及安装InterSystems Ensemble学习笔记(二) Ensemble创建镜像, 实现自动故障转移 一 ...

  7. 【LOJ】#2070. 「SDOI2016」平凡的骰子

    题解 用了一堆迷之复杂的结论结果迷之好写的计算几何???? 好吧,要写立体几何了 如果有名词不懂自己搜吧 首先我们求重心,我们可以求带权重心,也就是x坐标的话是所有分割的小四面体的x坐标 * 四面体体 ...

  8. 【POJ】2449.Remmarguts' Date(K短路 n log n + k log k + m算法,非A*,论文算法)

    题解 (搬运一个原来博客的论文题) 抱着板题的心情去,结果有大坑 就是S == T的时候也一定要走,++K 我发现按照论文写得\(O(n \log n + m + k \ log k)\)算法没有玄学 ...

  9. 8VC Venture Cup 2016 - Elimination Round F - Group Projects dp好题

    F - Group Projects 题目大意:给你n个物品, 每个物品有个权值ai, 把它们分成若干组, 总消耗为每组里的最大值减最小值之和. 问你一共有多少种分组方法. 思路:感觉刚看到的时候的想 ...

  10. Hadoop整理三(Hadoop分布式计算框架MapReduce)

    一.概念 MapReduce是一种编程模型,用于大规模数据集(大于1TB)的并行运算.概念"Map(映射)"和"Reduce(归约)",是它们的主要思想.它极大 ...