Javascript 使用 ExtJs 自动完成文本字段

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4415146/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 12:19:26  来源:igfitidea点击:

Auto complete textfield with ExtJs

javascriptweb-applicationsautocompleteextjs

提问by fastcodejava

How can I code a simple auto complete feature with ExtJs? If the field has address and they start typing stit should become street, etc

如何使用 ExtJs 编写简单的自动完成功能?如果该字段有地址并且他们开始输入st它应该变成街道等

回答by timdev

As Mitch suggests in his comment, you can use Ext.form.Combobox, properly configured, to do this. You won't need to bind anything to the keyup event, as Combobox will handle this for you.

正如米奇在他的评论中所建议的那样,您可以使用正确配置的 Ext.form.Combobox 来执行此操作。您不需要将任何内容绑定到 keyup 事件,因为 Combobox 会为您处理。

Here's the beginning of a config that should work. You'll need to provide an appropariate Ext.data.Store (or subclass thereof), along with a few other config values (displayField,valueField,queryParam, etc). All the necessary stuff is pretty well documented in the API docs)

这是应该可以工作的配置的开始。您需要提供适当的 Ext.data.Store(或其子类),以及一些其他配置值(displayField、valueField、queryParam 等)。所有必要的东西都在 API 文档中得到了很好的记录)

MyTypeahead = new Ext.form.ComboBox({
   triggerAction:'all',
   typeAhead:true,
   mode:'remote',
   minChars:2,
   forceSelection:true,
   hideTrigger:true
});

回答by wombleton

Here's the example that they have, they call it "live search".

这是他们拥有的示例,他们称之为“实时搜索”。

回答by DarkKnightFan

ExtJS : How to make combobox perform "Contains"/LIKE search see this

ExtJS:如何使组合框执行“包含”/LIKE 搜索,请参阅此内容