ExtJs和Java:更新组合框

时间:2014-03-20 15:46:11

标签: java javascript extjs

我有一个使用ExtJs创建的VehicleType组合框,当前使用以下代码在Java中调用的方法填充

VehicleType = this.VehicleType ;

Ext.apply(VehicleType , {
        valueProvider: {
            getValues: VehicleTypeService.getVehicleTypes
        },
        getDisplayValue: function(option) {
            return option.value;
        },
        getServerValue: function(option) {
            return option;
        },
        getInitValueParameters: function() {
            return [region, manufactuerTypeId, vehicleType];
        }
    },
    new Ext.controls.BaseSelectableMixin());
VehicleType.init();

被调用的Java方法是VehicleTypeService.getVehicleTypes,传递给Java方法的参数是函数getInitValueParameters。当我加载页面时工作正常,但是如果我在页面上更改上面的组合框(ManufactuerType:与只有不同值的VehicleType完全相同)我想根据选择的内容刷新VehicleType组合框

最好的解决方法是什么?

我尝试过扩展ComboSelectable以添加处理程序但无法使其正常工作

Ext.controls.VehicleTypeComboSelectable = Ext.extend(Ext.controls.ComboSelectable, {
    initComponent: function() {
        Ext.controls.VehicleTypeComboSelectable.superclass.initComponent.call(this);
        this.on("render", this.init.createDelegate(this));
    }
    ,init : function() {

    }
    ,handler : function() {

    }
});
Ext.reg('ownershiptypecomboselectable', Extador.controls.OwnershipTypeComboSelectable);

1 个答案:

答案 0 :(得分:0)

尝试使用组合框的事件监听器,然后使用商店的extraParams,如下所示:

PS:我无法看到你的ExtJS代码,所以我试图找出自己的方式。

// store definition
    var articleSub = new Ext.data.JsonStore({
    model: 'ArticleSubGroup',
    proxy: {
        type: 'ajax',
        url: '<?php echo base_url() ?>dashboard/promotion',
        reader: {
            type: 'json',
            root: 'ArticleSubGroup',
            idProperty: 'ID'
        }
    }
});

    // combobox definition
   {
    xtype: 'combobox',
    fieldLabel: 'MAL GRUBU',
    store: articleBase,
    id: 'art-base-group',
    queryMode: 'local',
    autoSelect: false,
    forceSelection: true,
    triggerAction: 'all',
    editable: false,
    valueField: 'PWG',
    displayField: 'PWG_BEZ',
    inputWidth: 240,
    margin: '10 0 0 0',
    listConfig: { cls: 'combo-dep' },
    listeners: {
        select: function(combo) {
            // here we are populating another combobox based on the 'basegroup' parameter
            articleSub.proxy.extraParams = {'basegroup': combo.getValue()}
            articleSub.load();
        }
    }
    }

    // here is the another combobox which is populating by above combobox
    // the tricks is 'store' parameter
    // we are posting url parameter then load the store in above
    {
    xtype: 'combobox',
    fieldLabel: 'ALT MAL GRUBU',
    store: articleSub,
    id: 'art-sub-group',
    queryMode: 'local',
    autoSelect: false,
    forceSelection: true,
    triggerAction: 'all',
    editable: false,
    valueField: 'PWUG',
    displayField: 'PWUG_BEZ',
    inputWidth: 240,
    margin: '10 0 0 0',
    listConfig: { cls: 'combo-dep' }
}