1. #1
    Sencha User
    Join Date
    Jul 2012
    Posts
    3
    Vote Rating
    0
    kbas is on a distinguished road

      0  

    Default Unanswered: sync localstorage with jsonp duplicate entries

    Unanswered: sync localstorage with jsonp duplicate entries


    Hello,
    i'm trying to learn sencha touch, i followed this tutorial http://lalexgraham.wordpress.com/201...p-proxy-store/ all is working but i have a problem with the pullrefresh plugin.

    view:
    Code:
    ....
     plugins: [
                        {
                            xtype: 'component',
                            refreshFn: function(plugin) {
                                console.log('refresh pulled');
                                this.fireEvent('refreshlist',this);
                            },
                            type: 'pullrefresh'
                        }
                    ]
    
    ...
    controller:
    Code:
    ....
     onRefreshList: function(target) {
            console.log('onrefreshlist angekommen');
            var remotestore = Ext.getStore('MarketRemoteStore');
            remotestore.on({load:'onMarketsStoreLoad', scope: this});
            remotestore.load({addRecord:true});
        },
      onMarketsStoreLoad: function() {
            console.log('onmarketsStoreLoad');
            var marketLocalStore = Ext.getStore('MarketLocalStore');
            var marketStore = Ext.getStore('MarketRemoteStore');
    
    
            marketStore.each(function(item){marketLocalStore.add(item.copy()); });
            marketLocalStore.sync();
    
    
            console.log(marketLocalStore.getCount());
            console.log(marketLocalStore);
        }
    model:
    Code:
    Ext.define('ss_test.model.market', {
        extend: 'Ext.data.Model',
    
    
        config: {
            idProperty: 'ID',
            identifier: 'uuid',
            useCache: false,
            fields: [
                {
                    name: 'Name',
                    type: 'string'
                },
                {
                    name: 'logo',
                    type: 'string'
                },
                {
                    name: 'ID',
                    type: 'auto'
                }
            ],
            proxy: {
                type: 'localstorage',
                id: 'ProxyMarket'
            }
        }
    });
    remotestore:
    Code:
    Ext.define('ss_test.store.MarketRemoteStore', {
        extend: 'Ext.data.Store',
    
    
        requires: [
            'Ext.data.proxy.JsonP',
            'ss_test.model.market'
        ],
    
    
        config: {
            model: 'ss_test.model.market',
            pageSize: 3,
            storeId: 'MarketRemoteStore',
            proxy: {
                type: 'jsonp',
                url: 'http://test.localdomain.com/api/market/.json',
                reader: {
                    type: 'json',
                    rootProperty: 'items',
                    useSimpleAccessors: false
                }
            }
        }
    });
    localstore:
    Code:
    Ext.define('ss_test.store.MarketLocalStore', {
        extend: 'Ext.data.Store',
    
    
        requires: [
            'ss_test.model.market'
        ],
    
    
        config: {
            model: 'ss_test.model.market',
            pageSize: 3,
            storeId: 'MarketLocalStore'
        }
    });
    always when i use the pullrefresh it adds the same data again to localstorage.
    i read in the forum and tried setting idProperty but nothing help.
    i also renamed the ID field in the model to MarketID and add a mapping:ID to it and tryed but the idProperty field is in localstorage always different.
    can someone help me whats the problem here

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,642
    Vote Rating
    899
    Answers
    3574
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Instead of blindly adding the recs to the localstorage store, I would check to see if there is a record with that ID. If there is then update the record data, if not then add it.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.