微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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之前使用.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐