cyberwombat
cyberwombat

Reputation: 40163

Fire event from hyperlink in Sencha Touch 2

How would I fire an event (I am wanting to switch card views) from a plain old html link?

If I reference the link by ID in my controls section no event I tried (click, tap) seems to be triggered.

Thanks!

Upvotes: 1

Views: 3425

Answers (3)

Roberto Rodriguez
Roberto Rodriguez

Reputation: 3357

I used simple Java Script to add a listener to the link.

First, I created an "activate" listener for the container component:

 ...
 listeners: {
        activate: function (newActiveItem, container, oldActiveItem, eOpts) {
            this.onActivate(newActiveItem, container, oldActiveItem, eOpts);
        }
    }
...

And here is my function:

onActivate: function (newActiveItem, mainNavView, oldActiveItem, eOpts) {
        var me = this;

        document.getElementById('logOutLink').addEventListener("click",
           function(){
               me.onLogOut();
           }, false);
       },
onLogOut:function(){
        alert('log out');
    }

Upvotes: 0

MRD
MRD

Reputation: 7184

Add a click listener to the panel containing the link. In the example the tag has the 'link' class. You can substitute it by your own class/id, as it's done in jQuery.

listeners: {
    scope: this,
    itemtap: this.onItemtapAction,
    click: {
       element: 'el',
       fn: function (e) {
          if (e.getTarget('a.link')) {
              // Switch cards here
          }
    }
}

Upvotes: 1

Pavel Podlipensky
Pavel Podlipensky

Reputation: 8269

Once you render the link you can add event listener in this way:

Ext.get('[link id here]').on('click', function(){...}, this);

UPDATE

If you want to fire an event once user clicked on hyperlink, you can simply add this.fireEvent('[name of event here]'); but be aware of this keyword meaning in this function, so you'll have an ability to add listener to it properly... Does it make sense?

Upvotes: 2

Related Questions