Results 1 to 5 of 5

Thread: How to handle 'activate' event in a ViewController

  1. #1
    Sencha - Sales Team
    Join Date
    Feb 2012
    Location
    Fort Myers, Florida
    Posts
    42

    Default Answered: How to handle 'activate' event in a ViewController

    trying to check out the new ViewController against a view in my app and I would like to trap the view's 'activate' event - is there an example of how to do this?

  2. Code:
    Ext.require('*');
    
    Ext.define('MyController', {
        extend: 'Ext.app.ViewController',
        alias: 'controller.my',
    
        onActivate: function() {
            console.log('Go', this.getView().title);
        }
    });
    
    Ext.define('MyView', {
        extend: 'Ext.panel.Panel',
        alias: 'widget.my',
        controller: 'my',
        listeners: {
            scope: 'this',
            activate: 'onActivate'
        }
    })
    
    Ext.onReady(function() {
    
        new Ext.tab.Panel({
            width: 600,
            height: 300,
            renderTo: document.body,
            defaultType: 'my',
            items: [{
                title: 'T1',
                html: 1
            }, {
                title: 'T2',
                html: 2
            }, {
                title: 'T3',
                html: 3
            }, {
                title: 'T4',
                html: 4
            }, {
                title: 'T5',
                html: 5
            }]
        });
    });

  3. #2
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,245
    Answers
    758

    Default

    Code:
    Ext.require('*');
    
    Ext.define('MyController', {
        extend: 'Ext.app.ViewController',
        alias: 'controller.my',
    
        onActivate: function() {
            console.log('Go', this.getView().title);
        }
    });
    
    Ext.define('MyView', {
        extend: 'Ext.panel.Panel',
        alias: 'widget.my',
        controller: 'my',
        listeners: {
            scope: 'this',
            activate: 'onActivate'
        }
    })
    
    Ext.onReady(function() {
    
        new Ext.tab.Panel({
            width: 600,
            height: 300,
            renderTo: document.body,
            defaultType: 'my',
            items: [{
                title: 'T1',
                html: 1
            }, {
                title: 'T2',
                html: 2
            }, {
                title: 'T3',
                html: 3
            }, {
                title: 'T4',
                html: 4
            }, {
                title: 'T5',
                html: 5
            }]
        });
    });
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  4. #3
    Sencha - Sales Team
    Join Date
    Feb 2012
    Location
    Fort Myers, Florida
    Posts
    42

    Default

    that's what I tried and it didn't work... but afterrender event worked - this was my issue

    Note This event is only fired if this Component is a child of a Ext.container.Container that uses Ext.layout.container.Card as it's layout or this Component is a floating Component.






  5. #4
    Sencha Premium User
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    2,425
    Answers
    20

    Default

    Evan, why do you use getView and and getReference? Why two method names?

    Could you use getView(reference) to overload the getReference method?

    Why itemId or some other query can't be used in place of reference?

  6. #5
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,245
    Answers
    758

    Default

    Because they do 2 things.

    getView gets the view attached to the controller. It has a specific meaning. Also, a view itself can also act as a referenceHolder, so Component also has a getReference method. Having component.getView seems a bit odd.

    We don't want to use queries for references because they're typically too fragile. They also rely on you providing your own scoping for queries. When using references, any scoping is automatically provided by virtue of having to look up the hierarchy as opposed to down.

    It's still easy to query the view if you like using the usual methods:

    Code:
    this.getView().query('foo');
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

Posting Permissions

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