1. #1
    Sencha User
    Join Date
    Jun 2009
    Posts
    84
    Vote Rating
    0
    nofx is on a distinguished road

      0  

    Default call controller function

    call controller function


    I have a controller defined like this:

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

        
    config: {

        },

        
    showTest: function() {
            
    alert('aaa');
        }

    }); 
    How can i call the showTest() function? I tried this:
    MyApp.controller.TestController.showTest();

    But this doesn't work. Anyone any idea how to do this..??

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,647
    Vote Rating
    899
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Where do you want to call it from? If from a view the view should not have that logic, the controller should act on events from the view.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Jun 2009
    Posts
    84
    Vote Rating
    0
    nofx is on a distinguished road

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    Where do you want to call it from? If from a view the view should not have that logic, the controller should act on events from the view.
    I want to call it from a DataView. I'm not using any Ext buttons or field on which i can add an event. I have a DIV with an onclick, like this:

    <div onclick="myController.myFunc({Username})">{Username}</div>

    These DIVs are generated by JSON data (from a store). I want to call my controller function directly from that DIV. Is that possible...??

  4. #4
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,647
    Vote Rating
    899
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    You should fire a custom event in the tap listener on the <div>. Your controller then can listen for the custom event.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  5. #5
    Sencha User
    Join Date
    May 2012
    Posts
    4
    Vote Rating
    0
    ssaqibmahmood@hotmail.com is on a distinguished road

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    You should fire a custom event in the tap listener on the <div>. Your controller then can listen for the custom event.
    First of all I am new on sencha platform. Kindly can you explain "Custom event in the tap listener on the <div>" with some example. And how to listen it on controller. kindly give some piece of code so i can implement it easily. Thanks.

  6. #6
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,647
    Vote Rating
    899
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    To listen for tap on an element:

    Code:
    component.element.on({
        scope : component,
        delegate : 'div',
        tap : function(e) {}
    });
    The delegate config can accept any dom selector (like div.myclass)

    To fire a custom event (like in the tap function) you can do:

    Code:
    this.fireEvent('divtap', this, e.getTarget());
    No win the controller you can listen to the divtap event on the component
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  7. #7
    Sencha User
    Join Date
    May 2012
    Posts
    4
    Vote Rating
    0
    ssaqibmahmood@hotmail.com is on a distinguished road

      0  

    Default


    Thanks for you help but I am still facing problem to fire a custom tap event on a div. I am trying to set a custom tap event against a div at Ext.define but it doesn't work. Actually i m not sure what to do on view level and what to do on controller level. I tried all possible variations and also read your other posts but it didn't solve my problem. Kindly give some full example which implements 'tap event on an element'. It will be great help for me. Thanks

  8. #8
    Sencha User
    Join Date
    May 2012
    Posts
    4
    Vote Rating
    0
    ssaqibmahmood@hotmail.com is on a distinguished road

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    Where do you want to call it from? If from a view the view should not have that logic, the controller should act on events from the view.
    Kindly can u further explain that what logic should be written on view to listen an event from an element like div.
    An early reply is requested. thanks

  9. #9
    Sencha User Skynet-tx's Avatar
    Join Date
    May 2012
    Location
    Sevastopol, Russia
    Posts
    20
    Vote Rating
    1
    Skynet-tx is on a distinguished road

      0  

    Default


    I done this. If you press button, then the handler call the controller. This very simply! Use this.
    tsvb2.app.getController('tsvb2.controller.playerEdit').editPlayer(0);
    tsvb2 - name of app,
    app - must not forget