电竞比分网-中国电竞赛事及体育赛事平台

分享

extjs的EditorGridPanel中的ComboBox列中顯示值的問題

 rkjx 2012-06-15
在項目中使用了extjs的editorgridpanel,但是其中的combobox在選擇了相應的選項后,grid中顯示的是值域(valueField)的值,而非意愿中的顯示域(displayField)的值,經(jīng)過一些搜索和嘗試后找到了一個比較好的解決方法——在定義帶combobox的列時配置其renderer的屬性。
Extjs代碼 復制代碼 收藏代碼
  1. var assistItemStore = new Ext.data.JsonStore({   
  2.                                 url:'assist.do',   
  3.                                 baseParams:{   
  4.                                     m : 'listAllLike',   
  5.                                     shopid: shopid ,   
  6.                                     subid: subid   
  7.                                 },   
  8.                                 root:'items',   
  9.                                 fields:[{   
  10.                                     name:'aux_name',   
  11.                                     mapping:'assistName'  
  12.                                 },{   
  13.                                     name:'aux_id',   
  14.                                     mapping:'assistid'  
  15.                                 }]   
  16.                             });  



Extjs代碼 復制代碼 收藏代碼
  1. {   
  2.                         header :'項目名稱',   
  3.                         width :100,   
  4.                         dataIndex :'aux_id',   
  5.                         editor : new Ext.form.ComboBox({   
  6.                             autoLoad:true,   
  7.                             triggerAction : 'all',   
  8.                             selectOnFocus : true,   
  9.                             allowBlank : true,   
  10.                             editable: true,   
  11.                             displayField:'aux_name',   
  12.                             valueField:'aux_id',   
  13.                             minChars:1,   
  14.                             queryParam:'subname',   
  15.                             typeAhead: true,   
  16.                             store: assistItemStore   
  17.                         }),   
  18.                         renderer: function(value,metadata,record){   
  19.                             var index = assistItemStore.find('aux_id',value);   
  20.                             if(index!=-1){   
  21.                                 return assistItemStore.getAt(index).data.aux_name;   
  22.                             }   
  23.                             return value;   
  24.                         }  


這樣寫之后,選擇之后grid中顯示了displayField的值,但最初從數(shù)據(jù)庫提取的值仍然顯示valueField的值,原因是store的數(shù)據(jù)是遠程取得的,在grid最初的render中還無法從store中查到相對應的displayField的值,于是打算用ajax異步取得displayField的值,但是異步的線程不造成阻塞,無法保證返回值之前能取得相應的數(shù)據(jù).后來想出另一個方法,為grid增加一個隱藏列,存放對應的值,在最初提取數(shù)據(jù)時能夠從中獲取要顯示的值.
Extjs代碼 復制代碼 收藏代碼
  1. {   
  2.                         header:'',   
  3.                         width:10,   
  4.                         dataIndex:'aux_name',   
  5.                         hidden:true   
  6.                     }, {   
  7.                         header :'項目名稱',   
  8.                         width :100,   
  9.                         dataIndex :'aux_id',   
  10.                         editor : new Ext.form.ComboBox({   
  11.                             autoLoad:true,   
  12.                             triggerAction : 'all',   
  13.                             selectOnFocus : true,   
  14.                             allowBlank : true,   
  15.                             editable: true,   
  16.                             displayField:'aux_name',   
  17.                             valueField:'aux_id',   
  18.                             minChars:1,   
  19.                             queryParam:'subname',   
  20.                             typeAhead: true,   
  21.                             store: assistItemStore   
  22.                         }),   
  23.                         renderer: function(value,metadata,record){   
  24.                             var index = assistItemStore.find('aux_id',value);   
  25.                             if(index!=-1){   
  26.                                 return assistItemStore.getAt(index).data.aux_name;   
  27.                             }   
  28.                             return record.get('aux_name');   
  29.                         }  



總感覺這個編輯框太小了,用著很不舒服,希望改進.

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約