How would one do html input tag autocomplete in Ext.js?

走远了吗. 提交于 2019-12-21 10:19:51

问题


If you're using the Ext.js library, how does one do autocomplete in input text areas?

More precisely, how would one do autocomplete based on iterative Ajax requests (like the jQuery autocomplete plugin where the Ajax option is set to an updating url).

Thoughts are appreciated and thank you for reading.


回答1:


Since bmoueskau provided a quite full featured implementation, I thought a more bare-bones example could help.

var store = new Ext.data.JsonStore({
    url: '/your/ajax/script/',
    root: 'data',  // the root of the array you'll send down
    idProperty: 'id',
    fields: ['id','value']
});

var combo = new Ext.form.ComboBox({
    store: store,
    displayField:'value',
    typeAhead: true,
    mode: 'remote',
    queryParam: 'query',  //contents of the field sent to server.
    hideTrigger: true,    //hide trigger so it doesn't look like a combobox.
    selectOnFocus:true,
    width: 250,
    renderTo: 'autocomplete'  //the id of the html element to render to.
                              //Not necessary if this is in an Ext formPanel.
});

The store will accept responses from your server formatted like this:

{
    "success": true,
    "data": [
        {
            "id": 10,
            "value": "Automobile"
        },
        {
            "id": 24,
            "value": "Autocomplete"
        }
    ]
}

Of course, you could also set up your store with an Ext.data.XMLReader if that's more your style.

I hope that gets you started. I can't stress enough the awesomeness of the Ext documentation. It's got some pertinent examples in addition to the combobox samples, which I used heavily when I first made some autocompleters.




回答2:


There is no separate autocomplete functionality that can be attached generically to inputs -- you would just use a ComboBox control with server-side filtering (you can use the "hideTrigger: true" config so that it still looks like a plain input). This is probably the closest example to what you'd want:

http://extjs.com/deploy/dev/examples/form/forum-search.html



来源:https://stackoverflow.com/questions/1313025/how-would-one-do-html-input-tag-autocomplete-in-ext-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!