extjs 如何有条件地筛选商店?

niwlg2el  于 2022-11-04  发布在  其他
关注(0)|答案(1)|浏览(162)

我是相当新的ExtJS和我有麻烦与我的商店。我有两个组合框上弹出,每一个设置为一个商店。

items: [
                {
                    xtype: 'combobox', itemId: 'facility', name: 'facilityId', fieldLabel: 'Facility', displayField: 'name', valueField: 'id', queryMode: 'local', allowOnlyWhitespace: false, forceSelection: true,
                    store: {
                        model: 'Common.model.Facility', autoDestroy: true, sorters: 'name'
                    },
                    listeners: {
                        change: function (field, newValue) { this.up('window').filterLocations(); }
                    }
                },
                {
                    xtype: 'combobox', fieldLabel: 'Location', name: 'locationId', displayField: 'name', valueField: 'id', queryMode: 'local', allowOnlyWhitespace: false, forceSelection: true,
                    store: {
                        model: 'Common.model.PrimaryLocation', autoDestroy: true, sorters: 'name'
                    },
                    // Strange hack from Sencha to get around filter-on-load issue http://www.sencha.com/forum/showthread.php?80079-Problem-to-filter-a-combobox-s-store-at-store-s-load-event
                    triggerAction: 'all', lastQuery: ''
                }
            ],

这里(我想)在另一个代码文件中引用了它(我现在只发布我关心的那个):

// Load comboboxes

        window.getFacilityId().getStore().load({
            scope: this,
            callback: function (records, operation, success) {
                if (!success) {
                    Ext.log({ level: 'error', msg: 'Error loading facility list', dump: operation });
                    var text = (operation.getError() ? operation.getError().response.responseText : operation.getResponse().responseText);
                    var msg = Ext.decode(text).message;
                    Ext.Msg.show({ title: 'Error', msg: 'Error loading facility data.<br>' + msg, buttons: Ext.Msg.OK, icon: Ext.Msg.ERROR });
                }
                else {

                    // Select first entry if only one

                    if (records.length == 1)
                        window.getFacilityId().setValue(records[0].get('id'));
                }
            }
        });

表单上有一个字段调用this,它有一个值需要进行比较,如果值为null或0,那么我真的不需要做任何事情,因为它实际上显示了数据库中的所有设施。但是,如果它不为null或0,那么我需要对商店进行筛选,以便仅显示列表中与要比较的值上的设施相匹配的单个设施。
如何使这个过滤器工作?为了简单起见,假设设施商店只有id和name字段,并假设我要与之进行比较的值是facilityId。
类似于:

if (facilityId == null)
  // What?

Thank you.
mxg2im7a

mxg2im7a1#

在存储上使用load方法之前,如果满足如下条件,请设置filter:

window.getFacilityId().getStore().setFilters({
  property: 'id',
  operator: '=',
  value: facilityId
});

相关问题