Results 1 to 2 of 2

Thread: sync localstorage with jsonp duplicate entries

  1. #1
    Sencha User
    Join Date
    Jul 2012
    Posts
    3
    Vote Rating
    0
      0  

    Default 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 - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,421
    Answers
    3901
    Vote Rating
    1271
      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 @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    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.

Tags for this Thread

Posting Permissions

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