2013-08-28 2 views
2

격자 안에 표시되는 정적 (하드 코딩 된) 값이 거의없는 콤보 상자가 있습니다.콤보 상자의 기본값을 설정하는 방법

기본적으로 콤보 상자의 첫 번째 값이 표시되어야합니다. 나는 몇 가지 시도했지만 작동하지 않습니다. 내가 먼저 StaticComboBox를 만든 다음

 var StaticComboBox = Ext.extend(Ext.form.ComboBox, { 
    mode: 'local', 
    triggerAction: 'all', 
    editable: false, 
    valueField: 'value', 
    displayField: 'label', 
    data: [], 
    initComponent: function() { 
    this.store = new Ext.data.ArrayStore({ 
     fields: ['value', 'label'], 
     data: this.data 
    }); 
    StaticComboBox.superclass.initComponent.call(this); 
    } 
}); 


    var cm = new Ext.grid.ColumnModel([ 
    { 
     id:'language', 
     header: "Language", 
     dataIndex: 'language', 
     width: 235, 
     menuDisabled: true, 
     editor: new StaticComboBox({ 
      name: 'Reasons', 
      data: [ 
      [0, 'Reason 1'], 
      [1, 'Second Reason'], 
      [2, 'Something else'] 
      ] 
     }), 

     listeners: { 
      load: function() { 
       //set the ComboBox value here 
       var combo = Ext.getCmp('language'); 
       combo.setValue("1"); 
      } 
      } 
    } 
]); 

답변

0

당신이 부하 이벤트 상점이 이미 작성의 원인이 얻을 것이다 않을 수 있습니다. 렌더링 또는 다른 것을 듣습니다. 여기

은 작업 예입니다 http://jsfiddle.net/4baem/3/

사용 Ext.data.Store 다음 데이터 레코드의 배열한다 :

new StaticComboBox({ 
     name: 'Reasons', 
     data: [{value: 0, label: 'reason1'}, {value: 1, label: 'reason2'}]  
}); 
관련 문제