How to read additional response data after storage sync

I have the following situation. I have a TreeStore that syncs with my server. The server response returns the modified node data with an additional "additional tasks" property (which stores information generated by the server for new nodes). How can I get this property value if all store listeners are already getting an instance of the record object and not the raw response data? I tried to add this extra field to my model, but when I check its value for records in the listener function, they show up 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 answer:

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

      

+3


source to share


2 answers


The store proxy always retains the original response from the most recent request. Try something like this and see if you need information.



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

      

+1


source


I faced the same problem. What I had to do was use the standard tree model property (I used cls

) for any custom data you try to load into the model. I could be wrong, but since I looked into this issue it seems that extjs is forcing the tree model to only use standard fields. They state:

If no model is specified, an implicit model will be created that implements Ext.data.NodeInterface. The default Tree fields will also be copied to the model to maintain their state. These fields are listed in the Ext.data.NodeInterface documentation.



However, from testing it seems that only standard fields are available, regardless of whether the model is specified. The only workaround I could find is to use a standard string type field, which I don't need for example cls

, although I would be interested to see if anyone has found a better way.

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

0


source







All Articles