1. #1
    Sencha User jep's Avatar
    Join Date
    Sep 2010
    Posts
    862
    Vote Rating
    21
    jep will become famous soon enough jep will become famous soon enough

      0  

    Default getting -1 for index on List itemtap

    getting -1 for index on List itemtap


    I'm trying to following code, which I THINK should give me a list and let me tap on the items.

    Code:
     <!DOCTYPE html>
     <html>
    
     <head>
        <meta charset="utf-8">
        <title id="title">test</title>
        <link rel="stylesheet" href="sencha-touch-beta-0.96/resources/css/ext-touch.css" type="text/css">
        <script type="text/javascript" src="sencha-touch-beta-0.96/ext-touch-debug.js"></script>
        <script type="text/javascript">
    
    Ext.setup({
        onReady: function(){
        
            var chooser = new Ext.List({
              data:[
                {text:'This is line 1'},
                {text:'This is line 2'},
                {text:'This is line 3'},
                {text:'This is line 4'},
                {text:'This is line 5'},
                {text:'This is line 6'},
                {text:'This is line 7'},
                {text:'This is line 8'},
                {text:'This is line 9'}
              ],
              itemSelector:'.listItemCls',
              tpl:[
                '<tpl for=".">',
                '<div itemIndex="{#}" class="listItemCls">{text}</div>',
                '</tpl>'
              ],
              listeners:{
                itemtap:function(dataview, index, item, e) {
                  console.log(index, item.getAttribute('itemIndex')-1);
                }
              }
            });
            
            var mainPanel = new Ext.Panel({
              fullscreen: true,
              layout: 'fit',
              items:[chooser]
            });
        }
    });
        </script>
    
     </head>
    
     <body></body>
    
     </html>
    But in the itemtap, it always returns -1 for the index. As you can see, I'm getting around it by setting an "itemIndex" attribute on my element. But I'm just wondering if this is correct behavior and I'm just not using the component correctly.

  2. #2
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    17,046
    Vote Rating
    657
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    You're not using it correctly. A list should be backed by a data store, check out the list example.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  3. #3
    Sencha User jep's Avatar
    Join Date
    Sep 2010
    Posts
    862
    Vote Rating
    21
    jep will become famous soon enough jep will become famous soon enough

      0  

    Default


    Argh. In the docs, nothing said "required" next to "store." I saw it in the example, but I thought it was like most other things in Sencha Touch - you can do it a billion different ways and this is just one way of doing it. It's too bad it MUST take that, as it bumps up the complexity level a bit. Things like this steepen the learning curve, and I've found it's already been fairly steeper than most modern technologies I've used.

    Still, thanks for the help! I'll apply myself to learning that bit of stuff now.

Similar Threads

  1. disclosure and itemtap on list
    By stefx in forum Sencha Touch 1.x: Discussion
    Replies: 1
    Last Post: 2 Sep 2011, 4:23 AM
  2. [CLOSED-206] Clicking on an empty list fires itemtap
    By meyerovb in forum Sencha Touch 1.x: Bugs
    Replies: 2
    Last Post: 14 Aug 2010, 5:06 AM
  3. list no index
    By ralf3000 in forum Sencha Touch 1.x: Discussion
    Replies: 0
    Last Post: 27 Jul 2010, 3:59 AM
  4. 3.1.1 - Combo List z index
    By TopKatz in forum Ext 3.x: Help & Discussion
    Replies: 8
    Last Post: 1 Mar 2010, 12:17 PM
  5. z-index of ComboBox list vs z-index of Ext.menu.Menu
    By christocracy in forum Ext 1.x: Help & Discussion
    Replies: 1
    Last Post: 1 Oct 2008, 10:05 AM

Thread Participants: 1