Skip to content Skip to sidebar Skip to footer

Accessing Functions In Viewcontroller From Form Created On-the-fly

The view controller will be active, but it will be controlling one sub-view of many other views, so I think there will be other active view controllers. By on-the-fly basically the

Solution 1:

I am not quite sure about your question. Here is what I understand: You have different views and there is no direct relation between them. But you want to reach each other view's controller. If so, please check this fiddle: https://fiddle.sencha.com/#fiddle/urg

Otherwise, I'd prefer you prepare a fiddle, which show your problem.

Ext.define('FirstPanel', {
            extend: 'Ext.panel.Panel',
            controller: 'FirstPanelController',
            layout: 'fit',
            itemId: 'firstPanel',
            items: [{
                xtype: 'button',
                text: 'FirstPanel Button',
                handler: 'FirstButtonClick'
            }]
        });
        Ext.define('FirstPanelController', {
            extend: 'Ext.app.ViewController',
            alias: 'controller.FirstPanelController',
            FirstButtonClick: function(button) {
                var me = this;
                varSecondPanelController = me.getView().mainView.down('#secondPanel').getController();
                SecondPanelController.FirstButtonClick();
                console.log('FirstButton Click');

            },
            SecondButtonClick: function() {
              alert('You are in FirstPanelController');  
            },
            init: function() {
                var me = this;     
            }
        });

        Ext.define('SecondPanelController', {
            extend: 'Ext.app.ViewController',
            alias: 'controller.SecondPanelController',
            SecondButtonClick: function(button) {
                var me = this;
                varFirstPanelController = me.getView().up().down('#firstPanel').getController();
                FirstPanelController.SecondButtonClick();
                console.log('SecondPanelController');

            },
            FirstButtonClick: function() {
                alert('You are in SecondPanelController');
            },
            init: function() {
                var me = this;     
            }
        });

        Ext.define('SecondPanel', {
            extend: 'Ext.panel.Panel',
            controller: 'SecondPanelController',
            layout: 'fit',
            itemId: 'secondPanel',
            items: [{
                xtype: 'button',
                text: 'SecondPanel Button',
                handler: 'SecondButtonClick'
            }]
        });


        Ext.define('MainPanel', {
            extend: 'Ext.panel.Panel',
            initComponent: function() {
              var me = this;
              me.items = [
                  Ext.create('FirstPanel', {
                      mainView: me
                  }),
                  Ext.create('SecondPanel')
              ]
              me.callParent();
            }
         });

Post a Comment for "Accessing Functions In Viewcontroller From Form Created On-the-fly"