autocomplete combobox extjs with remote ajax store

故事扮演 提交于 2019-12-12 09:21:50

问题


I want to add a combobox in my app with a remote store. I have a store that call a php script that returns data in json format and I linked it with my combobox. The store is autoLoaded but my combobox is still empty. Here's my store

// Define autocomplete model
Ext.define('modelloAC', {
    extend: 'Ext.data.Model',
    fields: [
        { name: 'telaio' }
    ]
});
// store auto complete
var autoCompleteStore = Ext.create('Ext.data.Store', {
    model: modelloAC,
    autoLoad: true,
    proxy: {
        type: 'ajax',
        url: 'script/request.php?operazione=gettelai',
        reader: {
            type: 'json',
            root: 'telai',
            totalProperty: 'results'
        }
    }
});

My PHP return a JSON array:

{"results":207,"telai":[{"telaio":"ZAR93200001271042"},{"telaio":"ZLA84000001738127"},{"telaio":"VF3WC9HXC33751301"},{"telaio":"W0L0AHL3555247737"}]}

My combobox:

    xtype: 'combo',
    name: 'telaio',
   //hideTrigger: true,
   store: autoCompleteStore,
   typeAhead: true,
   queryMode: 'remote',
   fieldLabel: 'Telaio'

My store loads perfectly but my combobox is empty, where's the problem?


回答1:


Need to add displayField and valueField in combo config:

...
displayField: 'telaio',
valueField: 'telaio',
...

Also model in your store is undefined now. Write it as a string:

...
model: 'modelloAC',
...


来源:https://stackoverflow.com/questions/16301198/autocomplete-combobox-extjs-with-remote-ajax-store

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