简体   繁体   English

ExtJS4组合框加载/存储问题

[英]ExtJS4 combobox loading/store issue

I'm seeing an issue with a combobox where I have a listener for the 'change' event. 我看到组合框有一个问题,其中有一个“更改”事件的侦听器。 When the event fires it runs a function that filters a store that powers another combobox to filter the values that are available in the 2nd combobox. 事件触发时,它将运行一个函数,该函数过滤存储,该存储为另一个组合框供电,以过滤第二个组合框中可用的值。

The idea is that when you pick from a short list in the first combobox, it pares down the choices in the second combobox. 这个想法是,当您从第一个组合框中的一个简短列表中进行选择时,它会缩减第二个组合框中的选择。

When the form loads, you can click the second combobox and see all the choices, that works great. 加载表单后,您可以单击第二个组合框并查看所有选择,效果很好。 When you then select something in the first combobox and then click the second combobox again, you see the appropriate shortened list but it's grayed out and the 'loading...' thing just spins and will never go away. 然后,当您在第一个组合框中选择某个内容,然后再次单击第二个组合框时,您会看到相应的缩短列表,但该列表变灰,并且“正在加载...”的内容只会旋转,并且永远不会消失。

If you load the form and pick something in the first combobox and then click the second combobox it will filter and show fine but you run into the issue of the loading problem I described above if you try to change your selection in the first box and click the second combobox again. 如果您加载表格并在第一个组合框中选择内容,然后单击第二个组合框,它将进行筛选并显示正常,但是如果您尝试在第一个组合框中更改选择并单击,则会遇到我上面描述的加载问题第二个组合框。

Please see the code below, I have this setup working on another screen and it doesn't seem to have this issue. 请查看下面的代码,该设置在其他屏幕上运行,并且似乎没有此问题。

I've got an ext store created like the following: 我已经建立了一个ext商店,如下所示:

var comboBreaker = Ext.create('Ext.data.Store', {
    autoLoad: false,
    remoteSort: true,
    remoteFilter: true,
    fields: [{
        name: 'id',
        mapping: 'item_id',
        type: 'int',
        useNull: false},
        'item_display_number','item_name', 'line_item_type_id', 'item_description'
    ],
    proxy:{
        type:'ajax',
        url: '/invoicer/data/getlineitems',
        reader: {
            type: 'json',
            successProperty: 'success',
            root: 'results',
            totalProperty: 'totalCount'
        },
        sorters:[{
            property:'item_display_number',
            direction:'ASC'
        }]
    }
});

This store powers a combobox, like so: 该存储为组合框供电,如下所示:

Ext.define('Writer.Form', {
    extend: 'Ext.form.Panel',
    alias: 'widget.writerform',

    requires: ['Ext.form.field.Text'],

    initComponent: function(){
        this.addEvents('create');
        Ext.apply(this, {
            activeRecord: null,
            frame: true,
            title: 'Line Item',
            id: 'writerform',
            fieldDefaults: {
                anchor: '100%',
                labelAlign: 'right'
            },
            items: [{
                xtype: 'combobox',
                fieldLabel: 'Item #',
                name: 'item_number',
                store: comboBreaker,
                displayField: 'item_display_number',
                valueField: 'id',
                allowBlank: false,
                forceSelection: true
            },{
                xtype: 'combobox',
                fieldLabel: 'Item Type',
                name: 'item_type',
                id: 'item_type',
                displayField: 'line_item_type',
                valueField: 'id',
                store: invoicer_lineItemTypeStore,
                forceSelection: true,
                labelWidth: 75,
                width: 200,
                listeners: {
                    change: {
                        fn: function() {
                            itemNumberFilter(comboBreaker);
                        }
                    }
                }
            }]
});

The itemNumberFilter() function takes a store and does filtering on it, here is that code: itemNumberFilter()函数接受一个存储并对其进行过滤,这是该代码:

function itemNumberFilter( store ) {
    var id = Ext.getCmp('item_type').getValue();
    store.remoteFilter = false;
    store.clearFilter();
    if ( id ) {

        store.filter('line_item_type_id', id);
    }
    store.remoteFilter = true;
    store.removeAll();
    store.load({
        scope: this,
        callback: function( records ) {
            console.log('Loaded records!');
            console.log(records);
        }
    });
}

I see the logged out records every time I change my selection in the first combobox and I can 'see' the results in the second combobox but they're always grayed out with the 'loading..' GIF showing. 每当我在第一个组合框中更改选择时,我都会看到已注销的记录,并且可以在第二个组合框中“看到”结果,但是它们始终显示为“正在加载。” GIF。

Edit: Video example: http://screencast.com/t/cUSHyFE6FIV 编辑:视频示例: http : //screencast.com/t/cUSHyFE6FIV

Edit: I believe this is the solution: 编辑:我相信这是解决方案:

lastQuery: '',
listeners: {
                        beforequery: {
                            fn: function(query) {
                                delete this.lastQuery;
                            }
                        }
                    }

Adding this to the combobox config fixes the issue. 将此添加到组合框配置可解决此问题。

Edit2: I ran into a second bug introduced by this, it was fixed by adding: Edit2:我遇到了由此引入的第二个错误,该错误通过添加以下内容得以修复:

this.clearValue();

to the beforequery function (above delete this.lastQuery). 到beforequery函数(删除this.lastQuery)。 This clears the value of the combobox each time the drop down arrow is clicked. 每次单击下拉箭头都会清除组合框的值。

Let's say you select item x in combo_1 and then item a in the pared down list in combo_2 . 比方说,你选择项xcombo_1 ,然后项目a在削减下拉列表combo_2 You then change the selection in combo_1 to y , which then changes the list of items again in combo_2 . 然后,将combo_1的选择combo_1y ,然后将其再次更改为combo_2中的项目列表。 Is a available in the new list in combo_2 that results from selecting item y in combo_1 ? a在新的列表中提供combo_2 ,从选择项目导致ycombo_1 Maybe it is an issue of trying to keep an item selected when it no longer exists in the list available to the combo. 可能是当项目在组合列表中不再存在时尝试保持选中状态的问题。

Have you tried clearing the selection in combo_2 before applying the filter? 在应用过滤器之前,您是否尝试过清除combo_2的选择?

您可以动态加载第二个combox框的存储,但是请确保将第二个combox框设置为“本地”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM