在ExtJS的ComboBox中设置服务器的值

时间:2011-03-22 12:16:53

标签: javascript extjs

我正在使用带有JsonReader的DataStore来填充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 = US,并且在加载表单时还可以在组合中选择所有其他选项。

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

一切正常,但组合中未选择BusinessUnit = US。

1 个答案:

答案 0 :(得分:0)

combo上的name字段与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);
    }
});