Sencha Touch 2.2 – pull to refresh plugin

By 4. Mai 2013 general No Comments

There is a plugin available for Touch called „pull to refresh“ which implements the function to pull down a list and refresh it.
To enable it just add a plugin object to the list:

plugins: [
            {
                xclass: 'Ext.plugin.PullRefresh',
                loadingText: 'laden...',
                pullRefreshText: 'Zum Aktualisieren herunterziehen...',
                releaseRefreshText: 'Zum Aktualisieren loslassen...',
          }
          ]

But I had a problem that the items duplicated themself every time I triggered the plugin.
There is a simple solution:
Just add an id field to your model, so that the plugin can check if the item is already in your list:

Ext.define('SIMOBILE.model.Test', { 
    extend:'Ext.data.Model', 
    config:{        
        fields:[ 
        { 
            name:'id',  
            type:'string', 
            convert: function(v,r){ 
                return r.data.name 
            } 
        },              
        { 
            name:'name',  
            type:'string' 
        }, 
        { 
            name:'count',  
            type:'int' 
        }     
        ]  
    } 
});