2011-03-22 41 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); 
    } 
});