如何在ExtJS中引用控件或控件的存储区?

hsvhsicv  于 2022-11-04  发布在  其他
关注(0)|答案(1)|浏览(161)

我有一个组合框,我需要在代码中访问存储区,以便对它应用筛选器。下面是组合框的定义。

//ItemGeneralPanel.js
Ext.define('myCompany.view.item.ItemGeneralPanel', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.myApp.ItemGeneralPanel',

    layout: 'vbox',
    bodyPadding: 4,
    defaults: { width: 800 },

    items: [
                {
                    xtype: 'combobox',
                    fieldLabel: 'Replenishment Source',
                    displayField: 'name',
                    valueField: 'id',
                    queryMode: 'local',
                    forceSelection: true,
                    bind: { value: '{item.sourceId}', store: '{replenishmentSourceList}' }
                }, 
    ]
});

我的ItemController中包含以下内容:

//ItemController.js
    stores: [
        'item.ItemList',
        'item.ReplenishmentSourceList'
    ],

我的商店看起来像这样:

//ReplenishmentSourceList.js
Ext.define('myCompany.store.item.ReplenishmentSourceList', {
    extend: 'Ext.data.Store',
    model: 'myCompany.model.Source',
    sorters: 'name'
});

该模型只有一个字段列表(Source.js):
如何在我的控制器中引用这个组合框,以便获得对其存储的引用,然后对返回的结果应用过滤器。类似于:

//ItemEditViewController.js
myFunction: function (facilId)  {

        this.lookup('replenishmentSourceList').getStore().load({
            scope: this,
            callback: function (records, operation, success) {
                if (!success) {
                    Ext.log({ level: 'error', msg: 'Error loading facility list', dump: operation });
                    var text = (operation.getError() ? operation.getError().response.responseText : operation.getResponse().responseText);
                    var msg = Ext.decode(text).message;
                    Ext.Msg.show({ title: 'Error', msg: 'Error loading Source data.<br>' + msg, buttons: Ext.Msg.OK, icon: Ext.Msg.ERROR });
                }
                else {

                    this.lookup('replenishmentSourceList').getStore().setFilters({
                        property: 'facilityId',
                        operator: '==',
                        value: 'facilId'

                    });

这不起作用,所以我想如果我能得到组合框,我可以做一些像这样的事情:我的引用到组合框.getStore().
有什么想法吗?

vlurs2pr

vlurs2pr1#

如果你想直接得到商店,你可以简单地使用storeId,并在创建的商店Ext.data.StoreManager.lookup('myStore')上执行查找,这将返回商店示例。
下面是一个示例,您可以在fiddle中试用(检查控制台,因为它使用store manager打印存储示例):

Ext.application({
    name: 'Fiddle',

    launch: function () {
        Ext.define('myCompany.store.item.ReplenishmentSourceList', {
            alias: 'store.replenishmentSourceList',
            extend: 'Ext.data.Store',
            sorters: 'name'
        });

        Ext.define('myCompany.view.item.ItemGeneralPanel', {
            extend: 'Ext.panel.Panel',
            alias: 'widget.myApp.ItemGeneralPanel',

            layout: 'vbox',
            bodyPadding: 4,
            defaults: {
                width: 800
            },

            items: [{
                xtype: 'combobox',
                fieldLabel: 'Replenishment Source',
                displayField: 'name',
                valueField: 'id',
                queryMode: 'local',
                forceSelection: true,
                store: {
                    type: 'replenishmentSourceList',
                    storeId: 'myStore'
                }
            }, ]
        });

        Ext.create({
            xtype: 'myApp.ItemGeneralPanel',
            renderTo: Ext.getBody()
        });

        console.log(Ext.data.StoreManager.lookup('myStore'));

    }
});

编辑以上是获取存储的一种方法,另一种方法是使用getView()从控制器获取comboboxpanel视图,然后获取存储。

下面是带控制器的代码(检查控制台):

Ext.application({
    name: 'Fiddle',

    launch: function () {

        Ext.define('MyApp.UserController', {
            alias: 'controller.user',
            extend: 'Ext.app.ViewController',
            myFunction: function (facilId) {
                console.log(this.getView())
                console.log(this.getView().down('#replenishmentCombo').getStore());
            }
        });

        Ext.define('myCompany.store.item.ReplenishmentSourceList', {
            alias: 'store.replenishmentSourceList',
            extend: 'Ext.data.Store',
            sorters: 'name'
        });

        Ext.define('myCompany.view.item.ItemGeneralPanel', {
            extend: 'Ext.panel.Panel',
            alias: 'widget.myApp.ItemGeneralPanel',
            controller: 'user',
            layout: 'vbox',
            bodyPadding: 4,
            defaults: {
                width: 800
            },
            listeners: {
                boxready: 'myFunction'
            },

            items: [{
                xtype: 'combobox',
                itemId: 'replenishmentCombo',
                fieldLabel: 'Replenishment Source',
                displayField: 'name',
                valueField: 'id',
                queryMode: 'local',
                forceSelection: true,
                store: {
                    type: 'replenishmentSourceList',
                    storeId: 'myStore'
                }
            }, ]
        });

        Ext.create({
            xtype: 'myApp.ItemGeneralPanel',
            renderTo: Ext.getBody()
        });

        // console.log(Ext.data.StoreManager.lookup('myStore'));

    }
});

相关问题