How to read additional response data after syncing store

I have the following situation. I have a TreeStore that is synced with my server. The server response returns the modified node data with an additional property 'additionalTasks' (which stores some server-generated info for new nodes). How can I get this property's value if all of the store's listeners get already an instantiated record object and not the raw response data ? I've tried adding this additional field to my model, but when I check it's value for the records in the listener function they're shown as null.

    Ext.define('ExtendedTask', {
        extend: 'Ext.data.NodeInterface',
        fields: [
            { name : 'additionalData', type : 'auto', defaultValue : null, persist : false}
        ]
    });

var store = Ext.create("Ext.data.TreeStore", {
    model : 'ExtendedTask',
    autoSync: false,
    proxy : {
        method: 'GET',
        type : 'ajax',
        api: {
            read : 'tasks.js',
            update : 'update.php',
            create : 'update.php'
        },
        reader : {
            type : 'json'
        }
    },
    listeners: {
        update : function(){
            console.log('arguments: ', arguments);
        }
    }
});

And this is my update.php response :

<?php
echo '[ { "Id" : 1,'.
    '"Name" : "Planning Updated",'.
    '"expanded" : true,'.
    '"additionalData": ['.
    '    {'.
    '        "Name" : "T100",'.
    '        "parentId" : null'.
    '    }'.   
    ']'.
']';
?>

The store's proxy always keeps the raw response from the most recent request. Try something like this and see if the information you need is there.

update : function(){
   console.log(this.proxy.reader.rawData);
}

I've faced the same issue. What I ended up having to do was use a standard tree model property (I used cls ) for whatever custom data you are trying to load into the model. I could be wrong but from the time I took looking to this issue, it seems that extjs is forcing a tree model to only use the standard fields. They state:

If no Model is specified, an implicit model will be created that implements Ext.data.NodeInterface. The standard Tree fields will also be copied onto the Model for maintaining their state. These fields are listed in the Ext.data.NodeInterface documentation.

However from testing it seems that only the standard fields are available regardless of if a model is specified. Only workaround I could find was to use an a standard string type field which I didn't need like cls , though I'd be interested to see if anyone has found a better way.

http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.TreeStore

链接地址: http://www.djcxy.com/p/80026.html

上一篇: 当同步功能被重写时,存储不会同步Sencha Touch 2.3

下一篇: 同步存储后如何读取其他响应数据