EXTJS组合框在展开后不按valueField选择

bel*_*laz 5 javascript combobox extjs

我写了一些非常好的代码,但我有一个奇怪的错误这是一个例子......


请看我的COMBOBOX BUG VIDEO


就像我说的那样,每次datachanged触发时都能正常工作 - 选择正确的索引并显示displayField但是,每次在组合框中键入一些文本后,当"datachanged"触发时,它都不会显示displayField.相反,它显示我启动的setValue方法的值.

奇怪的是,如果我没有输入文本并用鼠标更改选择,则没有错误.最后,只有在组合框中输入文本时才会出现这种情况.

有没有人听说过这个bug,有解决方案或者一些明智的建议?

代码 !

两个数据存储:

ficheDataStore = new Ext.data.Store({
    id: 'ficheDataStore',
    autoLoad: true,
    proxy: new Ext.data.HttpProxy({
        url: 'ficheDetail.aspx',      // File to connect to
        method: 'GET'
    }),
    baseParams: { clientId: clientId, Type: 'Fiche' }, // this parameter asks for listing
    reader: new Ext.data.JsonReader({   // we tell the datastore where to get his data from
        root: 'results'
    }, [
        { name: 'GUID', type: 'string', mapping: 'GUID' },
        { name: 'TagClient', type: 'string', mapping: 'TagClient' },
        { name: 'Nom', type: 'string', mapping: 'Nom' },
        { name: 'Compteur', type: 'string', mapping: 'CompteurCommunes' },
        { name: 'CompteurCommunesFacturation', type: 'string', mapping: 'CompteurCommunesFacturation' },
        { name: 'AdresseFacturation', type: 'string', mapping: 'AdresseFacturation' },
        { name: 'Codes', type: 'string', mapping: 'Codes' },
        { name: 'Observations', type: 'string', mapping: 'Observations' },
        { name: 'Adresse', type: 'string', mapping: 'Adresse' }

      ])
});

 communesDataStore = new Ext.data.Store({
    autoLoad: true,
    proxy: new Ext.data.HttpProxy({ url: 'ficheDetail.aspx?Type=Communes' }),
    reader: new Ext.data.JsonReader({ root: 'results' }, [{ name: 'Compteur' }, { name: 'Localisation'}])
});
Run Code Online (Sandbox Code Playgroud)

谁为第一个返回这样的东西:

  {results:[{"Nom":"cercle interieur"},{"Observations":""},{"Codes":" "},{"Adresse":"dd"},{"CompteurCommunes"
    :"1"},{"TagClient":"3-56"},{"GUID":"443609c6-d064-4676-a492-7baa7b4288d1"},{"AdresseFacturation":""}
    ,{"CompteurCommunesFacturation":"1"}]}
Run Code Online (Sandbox Code Playgroud)

对于后者 :

{"results":[{ "Compteur" : "1","Localisation" : "6200  ST ISIDORE"},{ "Compteur" : "2","Localisation"
 : "21340 CHANGE"},{ "Compteur" : "3","Localisation" : "1200  ELOISE"},{ "Compteur" : "4","Localisation"
 : "1200  ST GERMAIN SUR RHONE"},{ "Compteur" : "5","Localisation" : "75000 PARIS"},{ "Compteur" : "6"
,"Localisation" : "75001 PARIS 1ER ARRONDISSEMENT"}]}
Run Code Online (Sandbox Code Playgroud)

一个Combobox:

 var comb = new Ext.form.ComboBox(
             {
               store: communesDataStore,
               fieldLabel: 'Code postal',
               // hiddenName: 'Compteur',
               name: 'CompteurCommune',
               id: 'CompteurCommunes',
               width: 300,
               typeAhead: true,
               mode: 'local',
               minChars: 0,
               selecOnFocus: true,
               forceSelection: true,
               valueField: 'Compteur',
               displayField: 'Localisation',
               autocomplete: true,
               emptyText: 'Selectionnez un code postal',
               triggerAction: 'all',
               value: ''
              });
Run Code Online (Sandbox Code Playgroud)

在一个datachanged事件中,我设置了Combobox"CompteurCommunes" 的新值:

   ficheDataStore.addListener('datachanged', handleDatachangedEvent);

     function handleDatachangedEvent() 
       {
        try {
              comb.setValue(ficheDataStore.getAt(4).data.Compteur);                                                                                 
            }
        catch (err) { }
        }
Run Code Online (Sandbox Code Playgroud)

The*_*evs 3

这可能是因为当您在组合中输入随机数据时,它可能无法每次都找到正确的fieldValue。然后它停留在最后一个不存在的值。

在 datachanged 事件处理程序中执行 new setValue() 之前,尝试将 ComboBox 设置为任何现有值(在组合的数据存储中)。或者您可以尝试使用clearValue()方法来重置以前的(未定义的)valueField。

还有 initList() 方法可以将组合重置为初始状态。

编辑:经过一些测试,我发现: combo.store.clearFilter(); 必须在外部事件处理程序中的 setValue 之前使用。