javascript extjs4 在控制器中获取视图实例?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13884493/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 20:02:40  来源:igfitidea点击:

extjs4 get instance of view in controller?

javascriptmodel-view-controllerextjsextjs4extjs4.1

提问by reagan

I am trying to get an instance of my view within the controller. How can I accomplish this. The main reason I am trying to do this is that I have a grid in my view that I want to disable until a selection from a combobox is made so I need to have access to the instance of the view.

我正在尝试在控制器中获取我的视图实例。我怎样才能做到这一点。我尝试这样做的主要原因是我的视图中有一个网格,我想禁用它,直到从组合框中进行选择,所以我需要访问视图的实例。

Help?

帮助?

My controller:

我的控制器:

Ext.define('STK.controller.SiteSelectController', {
    extend: 'Ext.app.Controller',

    stores: ['Inventory', 'Stacker', 'Stackers'],
    models: ['Inventory', 'Stackers'],
    views: ['scheduler.Scheduler'],

    refs: [{
        ref: 'stackerselect',
        selector: 'panel'
    }],

    init: function () {
        this.control({
            'viewport > panel': {
                render: this.onPanelRendered
            }
        });
    },
    /* render all default functionality */
    onPanelRendered: function () {
        var view = this.getView('Scheduler'); // this is null?
    }
});

My view:

我的观点:

Ext.Loader.setConfig({
    enabled: true
});
Ext.Loader.setPath('Ext.ux', '/extjs/examples/ux');
Ext.require([
    'Ext.ux.grid.FiltersFeature',
    'Ext.ux.LiveSearchGridPanel']);

var filters = {
    ftype: 'filters',
    autoReload: false,
    encode: false,
    local: true
};

Ext.define('invtGrid', {
    extend: 'Ext.ux.LiveSearchGridPanel',
    alias: 'widget.inventorylist',
    title: 'Inventory List',
    store: 'Inventory',
    multiSelect: true,
    padding: 20,
    viewConfig: {
        plugins: {
            ptype: 'gridviewdragdrop',
            dragGroup: 'invtGridDDGroup',
            dropGroup: 'stackerGridDDGroup'
        },
        listeners: {
            drop: function (node, data, dropRec, dropPosition) {
                var dropOn = dropRec ? ' ' + dropPosition + ' ' + dropRec.get('ordNum') : ' on empty view';
            }
        }
    },
    features: [filters],
    stripeRows: true,
    columns: [{
        header: 'OrdNum',
        sortable: true,
        dataIndex: 'ordNum',
        flex: 1,
        filterable: true
    }, {
        header: 'Item',
        sortable: true,
        dataIndex: 'item',
        flex: 1,
        filterable: true
    }, {
        header: 'Pcs',
        sortable: true,
        dataIndex: 'pcs',
        flex: 1,
        filterable: true
    }]
});

Ext.define('stackerGrid', {
    extend: 'Ext.grid.Panel',
    alias: 'widget.stackerselect',
    title: 'Stacker  Select',
    store: 'Stacker',
    padding: 20,
    viewConfig: {
        plugins: {
            ptype: 'gridviewdragdrop',
            dragGroup: 'stackerGridDDGroup',
            dropGroup: 'invtGridDDGroup'
        },
        listeners: {
            drop: function (node, data, dropRec, dropPosition) {
                var dropOn = dropRec ? ' ' + dropPosition + ' ' + dropRec.get('ordNum') : ' on empty view';
            }
        }

    },
    columns: [{
        header: 'OrdNum',
        dataIndex: 'ordNum',
        flex: 1
    }, {
        header: 'Item',
        dataIndex: 'item',
        flex: 1
    }, {
        header: 'Pcs',
        dataIndex: 'pcs',
        flex: 1
    }],
    dockedItems: [{
        xtype: 'toolbar',
        dock: 'bottom',
        items: [{
            text: 'Submit',
            action: 'submit'
        }, {
            text: 'Reset',
            action: 'reset'
        }]
    }, {
        xtype: 'toolbar',
        dock: 'top',
        items: [{
            id: 'combo',
            xtype: 'combobox',
            queryMode: 'local',
            fieldLabel: 'Stacker',
            displayField: 'stk',
            valueField: 'stk',
            editable: false,
            store: 'Stackers',
            region: 'center',
            type: 'absolute'
        }]
    }]
});

Ext.define('STK.view.scheduler.Scheduler', {
    extend: 'Ext.panel.Panel',
    alias: 'widget.schedulerview',
    title: "Scheduler Panel",
    layout: {
        type: 'column'
    },

    items: [{
        xtype: 'inventorylist',
        width: 650,
        height: 600,
        columnWidth: 0.5,
        align: 'stretch'
    }, {
        xtype: 'stackerselect',
        width: 650,
        height: 600,
        columnWidth: 0.5
    }]
});

回答by lontivero

As I said, Extjs creates getter for your views (those listed in the controller's view array) and you get access to them:

正如我所说,Extjs 为您的视图(在控制器的视图数组中列出的那些)创建 getter,您可以访问它们:

var view = this.getSchedulerSchedulerView();

Once you have the view reference you can do this to get access to the contained grid:

获得视图引用后,您可以执行此操作以访问包含的网格:

var grid = view.down('.inventorylist');
grid.disable();