ExtJs:在ComboBox中搜索/过滤

编程入门 行业动态 更新时间:2024-10-10 01:24:27
本文介绍了ExtJs:在ComboBox中搜索/过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在ExtJs 2.3中遇到以下问题/问题:

I've the following problem / question in ExtJs 2.3:

我想在组合框中进行搜索。 我给你一个例子:

I'd like to do a search within a combobox. I'll give you an example:

ExtboData.names = [['Peter', 'Paul', 'Amanda']]; var store = new Ext.data.SimpleStore({ fields: ['name'], data: ExtboData.names }); var combo = new Ext.form.ComboBox({ name: '...', id: '...', store: store, displayField: 'name', typeAhead: true, mode: 'local', forceSelection: false, triggerAction: 'all', emptyText: '-', selectOnFocus: true, applyTo: '...', hiddenName: '...', valueField: 'name' enableKeyEvents: true, lastQuery: '', listeners: { 'keyup': function() { this.store.filter('name', this.getRawValue(), true, false); } } });

当我输入'a'时,只有'Paul'和'Amanda'在下拉菜单。所以换句话说,我正在寻找一个解决方案来过滤数据不仅通过条目的第一个字母,但也许通过使用像正则表达式(?)(像SQL ... LIKE'%a%') ...我还需要类型的onKeyDown - 事件为我的comboBox为了过滤我添加的每一个字母的结果。 我如何做到这一点?

When I would type in an 'a', there only should be 'Paul' and 'Amanda' in the "dropdown". So in other words I'm looking for a solution to filter the data not only by the entries' first letter, but maybe by using something like a regular expression (?) (like in SQL ... LIKE '%a%')...I also would need type of "onKeyDown"-event for my comboBox in order to filter the results on every single letter I add. How can I do that? Any ideas?

坦克:

Schildi

PS:不幸的是,我必须使用我当前版本的ExtJs(2.3),所以如果有一个解决方案,我的问题只是在以后的版本,我将不得不寻找另一种方法...

PS: Unfortunately I have to use my current version of ExtJs (2.3), so if there's a solution for my problem just in later versions, I would have to look for an other way...

推荐答案

我知道这是一个老问题,但这里最好的答案建议覆盖 doQuery 。应该避免覆盖私有方法,尤其是如果你要升级。相反,只需添加 beforequery 监听器以阻止 doQuery 清除过滤器。

I know this is an old question, but the best answers here recommend overriding doQuery. Overriding private methods should be avoided especially if you are ever going to upgrade. Instead, just add a beforequery listener to prevent doQuery from clearing the filter.

listeners: { 'keyup': function() { this.store.filter('name', this.getRawValue(), true, false); }, 'beforequery': function(queryEvent) { queryEventbo.onLoad(); // prevent doQuery from firing and clearing out my filter. return false; } }

更多推荐

ExtJs:在ComboBox中搜索/过滤

本文发布于:2023-11-13 04:35:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583443.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ExtJs   ComboBox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!