getting index value 0 from dataview any list itemtap from sencha touch

后端 未结 2 1745
误落风尘
误落风尘 2021-01-23 14:53

I am unable to get index value form the dataview:

    {          
              xtype: \'list\', 
              itemId: \'catList\',
              store: \'Categ         


        
2条回答
  •  盖世英雄少女心
    2021-01-23 15:33

    I tried and working perfectly for me, Let me share what i did.

    Model

    Ext.define('Myapp.model.Category', {
        extend: 'Ext.data.Model',
        config: {
            fields: [
                { name: 'cat_id', type: 'integer' },
                { name: 'category_name', type: 'string' },
                { name: 'created_date', type: 'string' },
                { name: 'order', type: 'integer' },
                { name: 'status', type: 'integer' },
                { name: 'deleted', type: 'integer' },
                { name: 'type', type: 'integer' }
            ]
        }
    });
    

    Store

    Ext.define('Myapp.store.Category', {
        extend: 'Ext.data.Store',
        requires: [
            'Myapp.model.Category'
        ],
        config: {
            storeId: 'category',
             model: "Myapp.model.Category",
             proxy: {
                type: "ajax",
                url : "http://alucio.com.np/trunk/dev/sillydic/admin/api/word/categories/SDSILLYTOKEN/650773253e7f157a93c53d47a866204dedc7c363?_dc=1376475408437&page=1&start=0&limit=25",
                reader: {
                    type: "json",
                    rootProperty: "data"
                }
            },
            autoLoad: true
        }
    
    });
    

    List

     {          
        xtype: 'list', 
        itemId: 'catList',
        store: Ext.create('Myapp.store.Category'),
        layout: 'fit',      
        itemHeight: 20,
        itemTpl: [
                  '
    ', '{category_name}', '
    '], listeners: { itemtap: function(list, index, target, record, e, eOpts){ console.log(record.get('cat_id')); } } }

    Output

    enter image description here

    As you can see itemtap function also printing correct cat_id

    UPDATE

    Based on your comment

    {    
       xtype :'panel',
       items : [{
           xtype : 'toolbar',
           itemId: 'categoryName'  // Give itemId  
          },
          {
           xtype: 'list', 
           itemId: 'catList',
           height : '100%',
           store: Ext.create('GoodNews.store.Category'),
           layout: 'fit',      
           itemHeight: 20,
           itemTpl: [
             '
    ', '{category_name}', '
    '], listeners: { itemtap: function(list, index, target, record, e, eOpts){ var catId = record.get('cat_id'); var categoryName = record.get('category_name'); // Set the title like this this.getParent().getComponent('categoryName').setTitle(categoryName); } } }] }

提交回复
热议问题