Results 1 to 6 of 6

Thread: Accessing a ViewController from another ViewController - best practices

  1. #1
    Sencha User silveralecs's Avatar
    Join Date
    Apr 2012
    Posts
    67
    Answers
    2

    Default Answered: Accessing a ViewController from another ViewController - best practices

    How can I access a ViewController from another ViewController?
    Do I have to use ComponentQuery to find the view and then call lookupController()?
    What are the best practices?

    Thanks

  2. I've answered myself this question by looking through ViewController's Listeners and Event Domains: http://docs.sencha.com/extjs/6.0/app...ntrollers.html

  3. #2
    Sencha User silveralecs's Avatar
    Join Date
    Apr 2012
    Posts
    67
    Answers
    2

    Default

    I've answered myself this question by looking through ViewController's Listeners and Event Domains: http://docs.sencha.com/extjs/6.0/app...ntrollers.html

  4. #3
    Sencha Premium Member
    Join Date
    Jun 2008
    Posts
    387

    Default

    It's best to not mingle viewcontrollers and their context. Any use case for this?
    I`m from Holland!

  5. #4
    Sencha User silveralecs's Avatar
    Join Date
    Apr 2012
    Posts
    67
    Answers
    2

    Default

    Lets say you have one big Panel, inside which you have other two smaller Panels:

    Panel 1 contains:
    - Panel 2
    - Panel 3

    You will have 3 controllers, one for each panel:
    - Controller 1 controls Panel 1
    - Controller 2 controls Panel 2
    - Controller 3 controls Panel 3

    Inside Panel 2 you will have a Button which validates a form, and if everything is ok, Panel 2 will hide and Panel 3 will show.

    In which controller will you place the logic of hiding Panel 2 and showing Panel 3?

  6. #5
    Sencha Premium Member
    Join Date
    Jun 2008
    Posts
    387

    Default

    I would hide panel 2 in the controller and fire an event to controller 3 to show his panel.
    I`m from Holland!

  7. #6
    Sencha User silveralecs's Avatar
    Join Date
    Apr 2012
    Posts
    67
    Answers
    2

    Default

    So you would use something like this?

    Code:
    Ext.define('App.Controller_2', {
        extend : 'Ext.app.ViewController',
        alias: 'controller.controller2'
        onButtonClick: function(){
             // validate form
             this.fireEvent('gotonextpanel');
        }
    });
    Code:
    Ext.define('App.Controller_3', {
        extend : 'Ext.app.ViewController',
        listen: {
            controller: {
                 controller2: {
                     gotonextpanel: function(){ // code }
                 }
            }
        }
    });

Similar Threads

  1. Accessing Viewcontroller from within renderer of grid
    By Necro-Engineering in forum Ext 5: Q&A
    Replies: 5
    Last Post: 20 Mar 2017, 2:45 AM
  2. Replies: 1
    Last Post: 11 Aug 2014, 5:17 AM
  3. Accessing Viewcontroller from a XTemplate (tpl) on a component?
    By Necro-Engineering in forum Ext 5: Q&A
    Replies: 3
    Last Post: 22 Jun 2014, 11:52 AM
  4. Replies: 1
    Last Post: 20 Jun 2014, 6:32 AM

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
  •