Results 1 to 3 of 3

Thread: how get data from a list when i tap 1 item

  1. #1
    Sencha User
    Join Date
    Aug 2011
    Posts
    6

    Default Answered: how get data from a list when i tap 1 item

    I'm stuck on my list. I do not know how to recieve data from it. I have the following code:

    Code:
    Ext.regModel('Contact', {
        fields: ['firstName', 'lastName']
    });
    
    
    var store = new Ext.data.JsonStore({
        model  : 'Contact',
        sorters: 'lastName',
    
    
        getGroupString : function(record) {
            return record.get('lastName')[0];
        },
    
    
        data: [
        {firstName: 'Tommy',   lastName: 'Maintz'},
            {firstName: 'Rob',     lastName: 'Dougan'},
            {firstName: 'Ed',      lastName: 'Spencer'},
            {firstName: 'Jamie',   lastName: 'Avins'},
            {firstName: 'Aaron',   lastName: 'Conran'},
            {firstName: 'Dave',    lastName: 'Kaneda'},
            {firstName: 'Michael', lastName: 'Mullany'},
            {firstName: 'Abraham', lastName: 'Elias'},
            {firstName: 'Jay',     lastName: 'Robinson'}
        ]
    });
    
    var list = new Ext.List({
        fullscreen: true,
       
        itemTpl : '{firstName} {lastName}',
        grouped : true,
        store: store,
               onItemTap: function(item) {
                Ext.Msg.alert('Tap', 'Disclose more info for ' + item.get('firstname'), Ext.emptyFn);
                }
    });
    But item.get('firstname') don't work.

  2. Remove your onItemTap code. That's an internal method that you shouldn't override. What you want to do is to 'listen' for the itemtap event and then have a handler function that runs when this event happens.

    Code:
    var list = new Ext.List({
        fullscreen: true,
        itemTpl : '{firstName} {lastName}',
        grouped : true,
        store: store,
        listeners : {
            itemtap : function(dataview, index, item, e) {
                var store = dataview.getStore(),
                    rec = store.getAt(index);
                    Ext.Msg.alert('Tap', 'Disclose more info for ' + rec.get('firstName'));
            }
        }
    });
    Also, you had a typo with the 'firstName' field. It has a capital 'N' so don't forget that.

  3. #2
    Sencha - Services Team
    Join Date
    Mar 2007
    Location
    Foristell, MO
    Posts
    1,121
    Answers
    14

    Default

    Remove your onItemTap code. That's an internal method that you shouldn't override. What you want to do is to 'listen' for the itemtap event and then have a handler function that runs when this event happens.

    Code:
    var list = new Ext.List({
        fullscreen: true,
        itemTpl : '{firstName} {lastName}',
        grouped : true,
        store: store,
        listeners : {
            itemtap : function(dataview, index, item, e) {
                var store = dataview.getStore(),
                    rec = store.getAt(index);
                    Ext.Msg.alert('Tap', 'Disclose more info for ' + rec.get('firstName'));
            }
        }
    });
    Also, you had a typo with the 'firstName' field. It has a capital 'N' so don't forget that.
    Jack Ratcliff
    Sencha Inc, Green bleeding Senchan

    How to report a bug:
    https://www.sencha.com/forum/showthr...o-report-a-bug

  4. #3
    Touch Premium Member
    Join Date
    May 2011
    Location
    Norfolk & DC
    Posts
    100
    Answers
    1

    Default

    Could also do something like:

    Code:
        itemtap     : function(record,index){
          var current = record.store.getAt(index);
          Ext.Msg.alert('Tap that','Some info about ' + current.firstName);
        }
    twitter.com/epiphanydigital #sencha #drupal #jquery #craftbeer #guitar #photography

Posting Permissions

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