1. #1
    Sencha Premium Member
    Join Date
    Mar 2013
    Posts
    44
    Vote Rating
    0
    Answers
    4
    BKrones is on a distinguished road

      0  

    Default Unanswered: Pull refresh receiving "new values" only

    Hi,
    i got a simple list filled with json-data and using pull-refresh to get new values.
    within the plugin-extension i am not able to compare old with new values.

    application:
    Code:
    Ext.Loader.setConfig({
    
    });
    
    
    Ext.application({
        models: [
            'TaskModel'
        ],
        stores: [
            'TaskStore'
        ],
        views: [
            'TaskList'
        ],
        name: 'CascadinDropDown',
    
    
        launch: function() {
    
    
            Ext.create('CascadinDropDown.view.TaskList', {fullscreen: true});
        }
    
    
    });
    model:
    Code:
    Ext.define('CascadinDropDown.model.TaskModel', {    extend: 'Ext.data.Model',
    
    
        requires: [
            'Ext.data.Field'
        ],
    
    
        config: {
            idProperty: 'ID',
            fields: [
                {
                    name: 'ID'
                },
                {
                    name: 'Username',
                    type: 'string'
                }
            ]
        }
    });
    store:
    Code:
    Ext.define('CascadinDropDown.store.TaskStore', {    extend: 'Ext.data.Store',
    
    
        requires: [
            'CascadinDropDown.model.TaskModel',
            'Ext.data.proxy.Ajax',
            'Ext.data.reader.Json'
        ],
    
    
        config: {
            autoLoad: true,
            autoSync: true,
            model: 'CascadinDropDown.model.TaskModel',
            storeId: 'TaskStore',
            proxy: {
                type: 'ajax',
                url: '/data/Task.json',
                reader: {
                    type: 'json',
                    rootProperty: 'data'
                }
            },
            listeners: [
                {
                    fn: 'onJsonstoreLoad',
                    single: true,
                    event: 'load'
                }
            ]
        },
    
    
        onJsonstoreLoad: function(store, records, successful, operation, eOpts) {
            var proxy = store.getProxy();
    
    
            // simulate data changing
            proxy.setUrl('data/Task2.json');
        }
    
    
    });
    view:
    Code:
    Ext.define('CascadinDropDown.view.TaskList', {    extend: 'Ext.dataview.List',
    
    
        requires: [
            'Ext.XTemplate'
        ],
    
    
        config: {
            store: 'TaskStore',
            itemTpl: [
                '<div>({ID}) Username: {Username}</div>'
            ],
            plugins: [
                {
                    type: 'pullrefresh'
                }
            ]
        }
    
    
    });
    pull-refresh extension:
    Code:
    Ext.define('CascadinDropDown.override.plugin.PullRefresh', {    override: 'Ext.plugin.PullRefresh',
        onLatestFetched : function(operation) {
            var store      = this.getList().getStore(),
                oldRecords = store.getData().items,
                newRecords = operation.getRecords(),
                i          = 0,
                length     = oldRecords.length,
                xLen       = newRecords.length,
                toRemove   = [],
                oldRecord, x, newRecord, found;
     
            this.callParent([operation]);
     
            for (; i < length; i++) {
                oldRecord = oldRecords[i];
                x         = 0;
                found     = false;
     
                for (; x < xLen; x++) {
                    newRecord = newRecords[x];
                    console.log(newRecord.get('Username') + ' ?-> ' + oldRecord.get('Username'));
                    if (newRecord.get('Username') === oldRecord.get('Username')) {
                        found = true;
                        break;
                    }
                }
     
                if (!found) {
                    toRemove.push(oldRecord);
                }
            }
     
            setTimeout(function() {
                store.remove(toRemove);
            }, 100);
        }
    });
    Task.json + Task2.json
    Code:
    {    "success" : true,
        "data"    : [
            {
                "ID"  : 1,
                "Username" : "Jason"
            },
            {
                "ID"  : 2,
                "Username" : "Pascal"
            },
            {
                "ID"  : 3,
                "Username" : "Delphii"
            }
        ]
    }
    
    {
        "success" : true,
        "data"    : [
            {
                "ID"  : 1,
                "Username" : "Jason"
            },
            {
                "ID"  : 2,
                "Username" : "Pascal"
            },
            {
                "ID"  : 3,
                "Username" : "Delphi"
            }
        ]
    }
    How do compare old values with new ones and add a css class to the changed records?

    Thank you very much

  2. #2
    Sencha - Support Team
    Join Date
    Oct 2011
    Posts
    4,003
    Vote Rating
    133
    Answers
    337
    fmoseley is a name known to all fmoseley is a name known to all fmoseley is a name known to all fmoseley is a name known to all fmoseley is a name known to all fmoseley is a name known to all

      0  

    Default

    What debugging have you done so far. I notice that you override the onLatestFetched function. Could it be that the call to this.callParent([operation]) is overwriting the data before you compare the data.
    Get more personalized support via a support subscription.

    Want to learn Sencha Touch 2? Check out
    Sencha training
    Sencha Touch in Action

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

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

    Need to include a test case use:
    The official Sencha Fiddle

  3. #3
    Sencha Premium Member
    Join Date
    Mar 2013
    Posts
    44
    Vote Rating
    0
    Answers
    4
    BKrones is on a distinguished road

      0  

    Default

    I have no clue how to debug properly.In my pullrefresh-plugin i simplyfied my code as much as possible:

    Code:
    Ext.define('TaskList.override.plugin.PullRefresh', {    override: 'Ext.plugin.PullRefresh',
        onLatestFetched : function(operation) {
        var store      = this.getList().getStore(),
                oldRecords = store.getData().items,
                newRecords = operation.getRecords();
             
            console.log(newRecords[0].get('Description'));
            console.log(oldRecords[0].get('Description'));
            this.callParent([operation]);
        }});
    This is always my output: Nevermind if i changed the description of the first record.
    What did i wrong here?

    Any other examples to compare old and new record?

    Thank you very much.

Thread Participants: 1

Tags for this Thread