现在的位置: 首页 > 综合 > 正文

关于Ext的Combo加载数据的问题。

2018年04月01日 ⁄ 综合 ⁄ 共 1305字 ⁄ 字号 评论关闭

 

  在combo的配置选项中有个mode,我们可以配置两个参数,local,remote 从字面意思上看,一个是本地加载,一个是远程加载。 
    于是就出现了一个问题,我用jsonStore去后台取数据的时候,认为数据是从后台来的所以设置mode为remote,但是combo并没有显示数据出来,从fireBug看到我拿到了正确的数据。试了很久都没解决,后来看到自己代码的store是这样的。

var store = new Ext.data.JsonStore({ 
      url:'getClientNameList.action', 
      root:'root', 
      autoLoad:true, 
      fields : [{name:'text'},{name:'value'}] 
  }); 

     突然蹦出个想法,会不会是数据已经取回本地了(注意autoLoad:true,)于是改动mode:'local' ,测试成功。于是想是不是自己想错了, mode 的方式remote 和 local是字面上的意思那样么,发现文档是这样写的: 
Acceptable values are: 'remote' : Default Automatically loads the store the first time the trigger is clicked. If you do not want the store to be automatically loaded the first time the trigger is clicked, set to 'local' and manually load the store. To
force a requery of the store every time the trigger is clicked see lastQuery. 'local' : ComboBox loads local data 

    意思大概是说,combo在第一次点击下拉按钮的时候会自动的load store ,竟然是这样为什么我设置成remote的时候点击下拉不会加载呢? 
    于是怀疑是不要吧autoLoad:true去掉,因为觉得既然combo把你load了就不需要了,后面发现想错了autoLoad去掉默认也是true,应该是写为false, 

总结

     最后几经周折发现所有的问题都在于:triggerAction ,默认情况下是查询的,当你设置了mode为remote的时候,实际上我们应当设置store为 
autoLoad:false 
    因为设置了这种方式combo会在第一此点击下拉的时候去远程读取数据,(实际上只有在设置了triggerAction:all)的时候才会,当默认的情况 
下,实际设置了triggerAction:query ,也就是查询的方式触发,combo只会在你输入了正确的combo里存在的那一项才会去后台加载数据给 
你。

    综合以上,一般如果我们要从服务器拿数据,而且想在第一次点击的时候才去取数据,应该做的设置是autoLoad:false ,triggerAction:all 
mode:'remote' 缺点就是无法使用combo的自动完成功能。

抱歉!评论已关闭.