2010-08-15 227 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