组合框上的 Extjs 4.2 远程过滤器

Extjs 4.2 remote filter on combobox

我有一个非常奇怪的远程存储问题,看起来像这样:

商店:

Ext.define('freetextOrder.store.Attachment', {
    extend: 'Ext.data.Store',
    model: 'freetextOrder.model.Attachment',
    autoLoad: false,
    proxy: {
        actionMethods: {
            create: "POST",
            read: "POST",
            update: "POST",
            destroy: "POST"
        },
        type: 'ajax',
        filterParam: 'filter',
        remoteFilter: true,
        autoSync: true,
        api: {
            read: 'ajax/Attachment/Cartarticle/Init',
            update: 'ajax/Attachment/Cartarticle/Update',
            create: 'ajax/Attachment/Cartarticle/Create',
            destroy: 'ajax/Attachment/Cartarticle/Destroy'
        },
        reader: {
            type: 'json',
            root: 'results',
            successProperty: 'success'
        },
        writer: {
            type: 'json',
            allowSingle: false
        },
        extraParams: {sid: config.sid}
    },
    listeners: {
        datachanged: function (store) {

            if (Ext.getCmp('attachmentGrid'))
                if (store.getCount() > 0) {
                    Ext.getCmp('attachmentGrid').show(); 
                } else {
                    Ext.getCmp('attachmentGrid').hide();
                }
        }
    }
});

型号:

Ext.define('freetextOrder.model.Attachment', {
    extend: 'Ext.data.Model',
    fields: [
        {name: 'id', type: 'int'},
        {name: 'cartarticle_id', type: 'int'},
        {name: 'orig_filename', type: 'string'},
        {name: 'upload_time', type: 'date'}
    ]

});

我的任务不可能完成,从商店加载过滤器:

 {
            xtype: 'combobox',
            queryMode: 'local',
            mode: 'local',
            fieldLabel: 'template',
            id: 'attachmentTemplate',
            name: 'test',
            store: Ext.create('freetextOrder.store.Attachment'),
            valueField: 'cartarticle_id',
            displayField: 'orig_filename',
            lazyInit: false,
            editable: true,
            invalidCls: '',
            listeners: {
                afterrender: function () {
                    var combo = Ext.getCmp('attachmentTemplate')

                    combo.getStore().clearFilter(true);
                    combo.getStore().addFilter({property: 'id', value: config.options.attTemplateIds});
                    combo.getStore().load();

                    console.log(combo.getStore().getById(49));
                }
            }
        }

问题是我正在尝试使用的事件,我尝试了一切让该死的东西加载商店元素,但它就是不会让步。

console.log(combo.getStore().getById(49)); returns 一个对象,以便加载商店。但不知怎的,它无法加载到它自己的组合框的选项中....

奇怪的部分是:

当我转到页面并执行 chrome 命令提示符中的代码时:

                 var combo = Ext.getCmp('attachmentTemplate')

                    combo.getStore().clearFilter(true);
                    combo.getStore().addFilter({property: 'id', value: config.options.attTemplateIds});
                    combo.getStore().load();

选项已加载。我已经筋疲力尽了。我必须将 config.options.attTemplateIds 传递给过滤器。这是唯一的要求。并且该值仅在定义了 xtype: 'combobox' 的情况下可用。

为了白痴的缘故,我什至尝试了围绕元素的最 hack 选项 setTimeout...仍然没有...真的很奇怪的行为。

有两件事或事件:第一是combo的afterRender,第二是store的load;

combo.getStore().getById(49) 必须在第二个事件之后使用;但是你把它放在组合的afterRender中,而商店的数据可能还没有!

因为我在一年后对这个问题感到困惑,又浪费了 4 小时试图让它工作,但没有成功.. 在我想起解决方法之后.. 我将它发布给其他人使用。

您可以使用额外的参数进行过滤。只需要做这样的事情

    var store = Ext.getStore('xxxx');
    store.getProxy().setExtraParam("xxx", newValue);
    store.load();