2011-03-22 21 views
0

我正在使用帶有JsonReader的DataStore來填充ComboBox,但正確的值沒有被標記爲選中。在ExtJS的ComboBox中設置服務器中的值

組合框:

{ 
    fieldLabel: 'Business Unit', 
    xtype:'combo', 
    width:167, 
    name: 'business_Unit', 
    hiddenName: 'businessUnit', 
    store: businessUnitStore, 
    displayField: 'buName', 
    valueField: 'buId', 
    mode: 'remote', 
    triggerAction: 'all', 
    typeAhead: false, 
    editable: false 
} 

和我在的形式使用JsonReader。

var leadReader = new Ext.data.JsonReader({ 
    root: 'data', 
    totalProperty: 'total', 
    id: 'leadId' 

}, [ 
    {name:'title', type: 'string'}, 
    {name:'firstName', type: 'string'}, 
    {name:'lastName', type: 'string'}, 
    {name:'designation', type: 'string'}, 
    {name:'business_Unit', type: 'string', mapping: 'businessUnit.buName'}, 
]); 

這是JSON響應:

{"data":{"leadId":22,"firstName":"fname","lastName":"lname","designation":"President","businessUnit":{"buId":4,"buName":"US","buDescription":""}},"success":true} 

我想BusinessUnit美國在下拉列表中選擇,也都可以在組合選擇其他選項當我加載形式=。

editForm.getForm().load({url:fetchUrl, method: 'GET'}); 

一切工作正常,除了沒有在組合中選擇BusinessUnit = US。

+0

請格式化您的代碼... – 2011-03-22 12:17:56

回答

0

組合中的名稱字段與json響應(business_Unit vs businessUnit)中的字段不匹配,但我也不認爲BasicForm.load將與嵌套對象一起使用。加載電話後,您可能需要手動加載它。

editForm.getForm().load({url: fetchUrl, method: 'GET', success: function(form, action) { 
     var combo = form.findField('business_Unit'); 
     combo.setValue(action.result.data.businessUnit.buiId); 
    } 
});