Results 1 to 3 of 3

Thread: Call controller method in ViewController

  1. #1
    Sencha Premium User
    Join Date
    Mar 2016
    Posts
    17
    Answers
    1

    Default Answered: Call controller method in ViewController

    Hi,

    How to call a function in a Controller from ViewController?

    Regards,
    Seyha

  2. Hi--

    There are a few ways to go about this.

    First, from within your view controller, you could simply lookup your controller and call the method:

    Code:
    Myapp.app.getController('...').someMethod(...)
    Another, probably better, option, would be to fire an event from within your view controller, and then add a listener to your controller for that event:
    Code:
    // fire event
    Ext.GlobalEvents.fireEvent('someevent', arg1, arg2, ...);
    
    // listener
    Ext.define('MyController', {
        extend: 'Ext.app.Controller',
        listen: {
            global: {
                someevent: 'onSomeEvent'
            }
        }
    });
    http://docs.sencha.com/extjs/6.0/6.0...ler-cfg-listen

    Thanks
    Joel

  3. #2
    Sencha User
    Join Date
    Nov 2014
    Posts
    3,120
    Answers
    446

    Default

    Hi--

    There are a few ways to go about this.

    First, from within your view controller, you could simply lookup your controller and call the method:

    Code:
    Myapp.app.getController('...').someMethod(...)
    Another, probably better, option, would be to fire an event from within your view controller, and then add a listener to your controller for that event:
    Code:
    // fire event
    Ext.GlobalEvents.fireEvent('someevent', arg1, arg2, ...);
    
    // listener
    Ext.define('MyController', {
        extend: 'Ext.app.Controller',
        listen: {
            global: {
                someevent: 'onSomeEvent'
            }
        }
    });
    http://docs.sencha.com/extjs/6.0/6.0...ler-cfg-listen

    Thanks
    Joel

  4. #3
    Sencha Premium User
    Join Date
    Mar 2016
    Posts
    17
    Answers
    1

    Default

    Dear Joel,Thanks so much for this.I have save my time a lot.Regards,Seyha

Similar Threads

  1. ExtJs5: Call Controller 2's method from Controller 1
    By gaurav.varshikar in forum Ext 5: Q&A
    Replies: 24
    Last Post: 15 Apr 2016, 12:23 AM
  2. Call Controller method
    By lbottoni in forum Ext 5: Q&A
    Replies: 4
    Last Post: 1 Feb 2016, 10:33 AM
  3. Replies: 5
    Last Post: 21 Nov 2014, 2:53 PM
  4. Replies: 7
    Last Post: 22 Apr 2014, 2:31 AM
  5. Call a method in a controller
    By dblv in forum Ext: Discussion
    Replies: 2
    Last Post: 30 Oct 2012, 11:43 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •