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

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

PLEASE WATCH MY 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',mapping: 'TagClient' },{ name: 'Nom',mapping: 'Nom' },{ name: 'Compteur',mapping: 'CompteurCommunes' },{ name: 'CompteurCommunesFacturation',mapping: 'CompteurCommunesFacturation' },{ name: 'AdresseFacturation',mapping: 'AdresseFacturation' },{ name: 'Codes',mapping: 'Codes' },{ name: 'Observations',mapping: 'Observations' },{ name: 'Adresse',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'}])
});

Who return something like this for the
first:

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

For the latter :

{"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"}]}

一个组合框:

 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: ''
              });

在datachanged事件中,我设置了ComboBox“CompteurCommunes”的新值:

   ficheDataStore.addListener('datachanged',handleDatachangedEvent);

     function handleDatachangedEvent() 
       {
        try {
              comb.setValue(ficheDataStore.getAt(4).data.Compteur);                                                                                 
            }
        catch (err) { }
        }
最佳答案
这可能是因为当您将随机数据输入到组合中时,它可能无法每次都找到正确的fieldValue.然后它停留在最后一个不存在的值.

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

还存在initList()方法以将组合重置为初始状态.

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

相关文章

前言 做过web项目开发的人对layer弹层组件肯定不陌生,作为l...
前言 前端表单校验是过滤无效数据、假数据、有毒数据的第一步...
前言 图片上传是web项目常见的需求,我基于之前的博客的代码...
前言 导出Excel文件这个功能,通常都是在后端实现返回前端一...
前言 众所周知,js是单线程的,从上往下,从左往右依次执行,...
前言 项目开发中,我们可能会碰到这样的需求:select标签,禁...