1. #1
    Sencha User
    Join Date
    Aug 2011
    Posts
    88
    Vote Rating
    0
    Marc-QNX is on a distinguished road

      0  

    Default Tap event not firing on nested components?

    Tap event not firing on nested components?


    I'm having an issue where the 'tap' event is not firing on nested components.

    For example, this works perfectly:

    Code:
    Ext.define('MyApp.view.Home', {
        extend: 'Ext.Panel',
        xtype: 'homeView',
    
    
        config: {
            fullscreen: true,
            layout: 'fit',
    
    
            items: [{
                xtype: 'dataview',
                itemTpl: '{label}',
                store: 'Items',
                scrollable: false,
                listeners: {
                    itemtap: function (dataview, index, item, e) 
                    {
                        alert('test');
                    }
                }
            }]
    
    
        },
    
    
    });
    However, if I do the following, the event never triggers

    Code:
    Ext.define('MyApp.view.Home', {
        extend: 'Ext.Panel',
        xtype: 'homeView',
        
        requires: [
            'MyApp.view.home.HomeDataview'
        ],
    
    
        config: {
            fullscreen: true,
            layout: 'fit',
    
    
            items: [{
                xtype: 'homedataview',
            }]
    
    
        },
    
    
    });
    Code:
    Ext.define('MyApp.view.home.HomeDataview', {
        extend: 'Ext.dataview.DataView',
        xtype : 'homedataview',
    
    
        config: {
            xtype: 'dataview',
            itemTpl: '{label}',
            store: 'Items',
            scrollable: false,
            listeners: {
                itemtap: function (dataview, index, item, e) 
                {
                    alert('test');
                }
            }
        },
    
    
    });
    Am I missing something?

    I also tried to do this from the controller via this.control() but no luck there either:

    Code:
    Ext.define('MyApp.controller.Home', {
        extend: 'Ext.app.Controller',
    
    
        views : [
            'Home',
        ],
    
    
        stores: [
            'Items'
        ],
    
    
        refs: [
            {
                ref     : 'homeView',
                selector: 'homeView',
                xtype   : 'homeView'
            },
        ],
    
    
        init: function() {
            this.getHomeView().create();
    
    
            this.control({
                'homedataview': {
                    tap: this.onItemTap
                },
        });
        },
    
    
        onItemTap: function (dataview, index, item, e) 
        {    
            alert('test')'
        }
    
    
    });
    Any thoughts?

  2. #2
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243
    Vote Rating
    10
    TommyMaintz will become famous soon enough TommyMaintz will become famous soon enough

      0  

    Default


    You should not define listeners inline in the config object when defining your view. You either define them when creating an instance of your class (like you did in your first example), or when you use the MVC structure (recommended) you can use this.control. The reason your last example doesn't work is because you are using tap instead of itemtap.

    PHP Code:
    Ext.define('MyApp.controller.Home', {
        
    extend'Ext.app.Controller',

        
    views : [
            
    'Home',
        ],

        
    stores: [
            
    'Items'
        
    ],

        
    refs: [
            {
                
    ref     'homeView',
                
    selector'homeView',
                
    xtype   'homeView'
            
    },
        ],

        
    init: function() {
            
    this.getHomeView().create();

            
    this.control({
                
    'homedataview': {
                    
    itemtapthis.onItemTap
                
    }
            });
        },

        
    onItemTap: function (dataviewindexiteme) {    
            
    alert('test');
        }
    }); 

  3. #3
    Sencha User
    Join Date
    Aug 2011
    Posts
    88
    Vote Rating
    0
    Marc-QNX is on a distinguished road

      0  

    Default


    Hi Tommy.

    Quote Originally Posted by TommyMaintz View Post
    You should not define listeners inline in the config object when defining your view. You either define them when creating an instance of your class (like you did in your first example),
    Thanks for this.. since they were both done under config I didn't notice the difference until now.

    Quote Originally Posted by TommyMaintz View Post
    or when you use the MVC structure (recommended) you can use this.control. The reason your last example doesn't work is because you are using tap instead of itemtap.
    I have a personal problem with using this.control(). Although I understand the reason for it, I can't bring myself to use it as it requires the controller to have knowledge of the internal workings of the view -- which is in itself a contradiction to MVC. The entire point is to separate the view from the controller and, if in the future, I wish to change the view, I should not have to change the controller.

  4. #4
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243
    Vote Rating
    10
    TommyMaintz will become famous soon enough TommyMaintz will become famous soon enough

      0  

    Default


    You should not think of a client-side MVC framework as if it is a server-side one. In a client-side app, all we want to do is listen for things happening on views (and other controllers) and react to it. The control method uses component queries, meaning that if the nesting/structure of your view changes, your queries will still work. This allows you to easily modify your views without having to update your controllers. I would fully agree with you if you meant that views should never be aware of controllers.

    Trying to bring a server side architecture to the client side causes a lot of problems (we actually did this in the old MVC architecture in 1.1). I think you would find that if you gave the new MVC architecture a chance (including this.control, refs, firing application events instead of dispatching, etc), you would soon find out that it is much much more suitable for building rich client side apps.

  5. #5
    Sencha User
    Join Date
    Aug 2011
    Posts
    88
    Vote Rating
    0
    Marc-QNX is on a distinguished road

      0  

    Default


    I actually thought the 1.1 MVC was pretty good. Yes there are some problems, but there are ways around most of them. I agree that the view should not know the controller's architecture, and the application events are great for that.

    Hopefully the MVC sessions at SenchaCon will clarify the new MVC a bit more and maybe some of these hesitations will go away.

Thread Participants: 1