2010-08-15 114 views
6

我怎樣才能從我的JSON商店(遠程)加載默認值到組合框, 我已經嘗試加載商店之前呈現組合,並使用setValue() 我想我的組合在商店中顯示的第一個結果 PLZ告訴我這樣做,並感謝名單以正確的方式加載組合框的默認值extjs

回答

14

您需要的value屬性設置爲第一要素的保值加載後

Ext.ns('MyNamespace'); 

MyNamespace.MyComboBox = Ext.extend(Ext.form.ComboBox, { 
    displayField: 'displayValue', 
    triggerAction: 'all', 
    valueField: 'ID', 

    initComponent: function() { 
    this.store = new Ext.data.JsonStore({ 
     url: 'url', 
     baseParams: { 
     //params 
     }, 
     fields: [ 
     {name:'ID', mapping: 'ID', type: 'int'}, 
     {name:'displayValue', mapping: 'displayValue', type: 'string'}, 
     ], 
     root: 'root' 
    }); 

    var me = this; 
    this.store.on('load',function(store) { 
     me.setValue(store.getAt(0).get('ID')); 
    }) 

    MyNamespace.MyComboBox.superclass.initComponent.call(this); 

    this.store.load(); 
    } 

}); 
+0

感謝這項工作很好 – cranberies 2010-08-15 21:44:57