javascript - 带有组合框的 ExtJS 过滤器错误

标签 javascript extjs web filter

我的 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'。这是更新后的 fiddle :Simple Fiddle

关于javascript - 带有组合框的 ExtJS 过滤器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24246069/

相关文章:

javascript - 为不同的 jquery slider 设置不同的宽度

c# - 如何在 jqgrid 中添加新的按钮/图像列

javascript - 在extjs 4.2中设置折线系列图表中的线条颜色

javascript - 如何使用 dataIndex Extjs 4 查找列索引

javascript - ExtJS 中的日期验证

javascript - Chart.js 中的自定义字母数字值?

html - 设置有序列表的样式,并将数字放入列表项中

javascript - 如何将字符串拆分为特定字节大小的 block ?

javascript - 按下按钮时等待 3 秒,然后提交 javascript

security - 当我有两个 CSP(内容安全策略)策略 - header 和元时会发生什么?