2

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 Answers 2

6

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 
}
Sign up to request clarification or add additional context in comments.

Comments

0

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!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.