ExtJS过滤器的错误与组合框

ExtJS filter bug with comboboxes

本文关键字:组合 错误 过滤器 ExtJS      更新时间:2023-09-26

我的ExtJS应用程序有一个问题。首先是代码

var typeStore = Ext.create('Ext.data.Store', {
fields: ['id', 'name'],
data: [
    {id: 1, name: 'type1'},
    {id: 2, name: 'type2'}
]
})
var mainStore = Ext.create('Ext.data.Store', {
fields: ['id', 'name', 'typeId'],
data: [
    {id: 1, name: 'item1', typeId: 1},
    {id: 2, name: 'item2', typeId: 1},
    {id: 3, name: 'item3', typeId: 2},
    {id: 4, name: 'item4', typeId: 2}
]
})
Ext.application({
name : 'Fiddle',
launch : function() {
    // Ext.Msg.alert('Fiddle', 'Welcome to Sencha Fiddle!');
    Ext.create('Ext.container.Viewport', {
        items: [
            Ext.create('Ext.form.ComboBox', {
                    fieldLabel: 'type',
                    store: typeStore,
                    valueField: 'id',
                    displayField: 'name',
                    listeners: {
                        select: function(combo, records, eOpts)
                        {
                            mainStore.clearFilter();
                            mainStore.filter([
                                Ext.create('Ext.util.Filter',
                                    {
                                        filterFn: function(record)
                                        {
                                            console.dir(record);
                                            var mainId = record.get('id');
                                            var typeId = record.get('typeId');
                                            var type = records[0].get('id');
                                            var tmpRes = (typeId == type);
                                            return tmpRes;
                                        },
                                        root: 'data'
                                    })
                            ])
                        }
                    }
                }),
                Ext.create('Ext.form.ComboBox', {
                    fieldLabel: 'item',
                    store: mainStore,
                    valueField: 'id',
                    displayField: 'name'
                }) 
        ]
    })
}
});

你有两个组合框。第一个字段的值应该过滤第二个字段。当您在第一个框中选择一个条目时,它会正确过滤第二个框,直到您在第二个框中选择一个条目。当您再次更改第一个组合框中的值时,第二个组合框中将没有条目。

不知何故,过滤器没有重置。你有什么办法解决这个问题吗?

我使用ext 4.2.1。

只需添加queryMode: 'local' .这里是更新的小提琴:简单的小提琴