Results 1 to 9 of 9

Thread: call controller function

  1. #1
    Sencha User
    Join Date
    Jun 2009
    Posts
    84
    Vote Rating
    0
      0  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Vote Rating
    1272
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  3. #3
    Sencha User
    Join Date
    Jun 2009
    Posts
    84
    Vote Rating
    0
      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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Vote Rating
    1272
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  5. #5
    Sencha User
    Join Date
    May 2012
    Posts
    4
    Vote Rating
    0
      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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Vote Rating
    1272
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  7. #7
    Sencha User
    Join Date
    May 2012
    Posts
    4
    Vote Rating
    0
      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
      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
      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

Posting Permissions

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