ExtJS Combobox 中Store动态传参数

ExtJS 中有时需要动态传递除了Page信息外的其它参数问题。
1. 依据不同参数load Store;
  use : baseParams 和 Store 的 beforeload事件。
2. 解决key事件;

示例代码,注意红色部分:(此处使用了WCF后台处理 ,WCFJsonReader请参阅博客园小庄)
    var readerSupplier = new Ext.data. WCFJsonReader({
        root: 'data', id: 'SupplierID', totalProperty: 'totalCount',
        fields: [
                    { name: 'SupplierID', type: 'int' },
                    { name: 'SupplierName', type: 'string' }
                ]
                });
    
    var _strSupplier = '';
    var SupplierStore = new Ext.data.Store({
        proxy: new Ext.data.WCFHttpProxy({
            url: '/Services.svc/GetSuppliersList'
        }),
        reader: readerSupplier,
        remoteSort: true,
        baseParams: { limit: 20, nameparam: _strSupplier } //
    });
    SupplierStore.on("beforeload", function() {
        SupplierStore.baseParams = { nameparam: _strSupplier };
    });
    
    comboSupplier = new Ext.form.ComboBox({
        store: SupplierStore,
        displayField: 'SupplierName',
        valueField: 'Supplier',
        hiddenField: 'Supplier',
        mode: 'local',
        triggerAction: 'all',
        emptyText: 'Type Supplier Code',
        selectOnFocus: true,
        value: '',
        width: 120,
        hideTrigger: true,
        applyTo: 'ddlSupplier',
       pageSize:20,
        onKeyUp: function(e) {
            _strSupplier = comboSupplier.getRawValue();
            if (_strSupplier == "") return;
            var k = window.event.keyCode;
            if (k != 37 && k != 38 && k != 39 && k != 40 && k != 13) {
                var request = { start: 0, limit:20, nameparam: _strSupplier };
                SupplierStore.reload({ params: request });
                setTimeout('', 500);
            }
        }
    });

你可能感兴趣的:(combobox)