2
votes

How to call controllers function from view while loading in sencha touch i have tried like below please help me out

Here is my listener in my view class

config: {
    listeners:{
        populateData:function(){
            populateDashBoardData();
        }
    },

Here is my method in controller

   populateDashBoardData: function () {
     //some functionlaity

    },
2

2 Answers

6
votes

Fire a custom event and handle that in controller

View (xtype : 'dashBoard') as i assumed

config: {
    // remaining of your configurations
    listeners:{
        initialize:function(){
            this.fireEvent('onPopulateDashBoardData', this);
        }
     }
},

Controller

config : {
    refs : {
        // as i assumed dashBoard is the xtype of the view
        DashBoard : 'dashBoard'
    },
    control : {
        DashBoard : {
            onPopulateDashBoardData : 'populateDashBoardData'
        }
    }
},

populateDashBoardData: function() {
    //some functionlaity 
}
0
votes

I 've been trying to do the same task with fireevent() but as I am quite new on Sencha I haven't managed to do it (I wanted to add an event listener to a .class). I found another way to do it, I don't know if there are recomendations for do not do it on that way, but it looks quite safe to me, this would be my view:

 
{      
    id: 'anime_svg',                 
    html:
        '' +
         ...
        ',
    listeners: {
    element: 'element',
    delegate: '.badge',
    tap: function(){
        appName.app.getController('controllerName').config.control.myMethod() 
    }
    ...
 

So yes, pretty basic access of the controller method but works and helps me isolating logic from view to controller, I would appreciate if someone thinks it is a bad idea to do it like that to tell me let me know and why...

thanks!