【问题标题】:ExtJS filter bug with comboboxes带有组合框的 ExtJS 过滤器错误
【发布时间】:2014-06-16 22:48:08
【问题描述】:

我的 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。

【问题讨论】:

    标签: javascript extjs web filter


    【解决方案1】:

    只需添加queryMode: 'local'。这是更新后的小提琴:Simple Fiddle

    【讨论】:

    • 非常感谢。就这么简单:) 你解决了我的头疼问题。
    猜你喜欢
    • 2012-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多