7

I've been unable to figure out how to manually fire DOM events. Here, for example, is my attempt to fire the "click" event for a li

Ext.DomQuery.select('#mapRoutesPanel ol li:nth-child('+(index+1)+')')[0].click();

It's working fine on google chrome, but when i build android native app of same application it gives me error

Uncaught TypeError: Object #<HTMLLIElement> has no method 'click'
user1812198
  • 121
  • 1
  • 4
  • Did you try http://stackoverflow.com/questions/16145882/extjs-manually-firing-click-event-button-param-is-different-from-mouse-click ? – Himanshu Tyagi Sep 02 '14 at 13:52

4 Answers4

1

Ext JS provides its methods for search elements in DOM tree.


Look Sencha Fiddle - its sencha touch app, i tested it on my android(opera) and iphone(safari) its work for me


Something like this:

var liElement = Ext.get('mapRoutesPanel').down('ol li:nth-child(' + (index + 1) + ')');
Igor Semin
  • 2,486
  • 1
  • 20
  • 21
0

Have you tried Ext.dom.Element-method-fireEvent?

Ext.DomQuery.select('#mapRoutesPanel ol li:nth-child('+(index+1)+')')[0].fireEvent('click')
0

Not all touch device browsers/apps support the click event because it is a mouse event. Why don't you try using Sencha's normalized event system to bind a click handler to the component, you can then check if the <li/> was clicked inside the component's click event handler.

Sencha has already done the work for us so we can handle clicks & taps in the same manner, so take advantage of it.

Btw, event delegation from a parent element is usually more performant than binding event handlers to a bunch of different DOM elements. It looks like your binding events to elements in a loop, this is a bad practice. I just wanted to point that out too.

Here is a code example:

var cmp = Ext.getCmp('someComponentId');
cmp.on('click', function(me, event) {
    if (event.currentTarget.tagName == "LI") {
        // do something since the <li/> tag was clicked.
        // event.currentTarget will be the <li/> DOM element,
        // feel free to do with it as you please :)
    }
}
macguru2000
  • 2,042
  • 2
  • 18
  • 27
-2

I did as below in my case.

Below is the sample html code of div with li s.

<div class="menu1" id="menu1">
  <ul>
    <li id="students_tab">Students</li>
    <li id="emps_tab">Employees</li>
  </ul>
</div>

And below is the extjs code to add click event to li element.

<script type="text/javascript">
   Ext.onReady(function(){
     var tabs= Ext.query("li", "menu1");
     Ext.each(tabs, function(item){
         var el = Ext.get(item);
         el.on("click", function(){
            var tabName = this.id.substr(0, this.id.indexOf("_"));
            alert("U have clicked on "+ tabName + " tab");
         });
     });
  });
</script>
Srikanth
  • 471
  • 2
  • 14