PDA

View Full Version : Treestore node remains after unsuccessful autosync



gemerson
12 Dec 2012, 6:55 AM
When no server exceptions occur I have a TreePanel/Treestore/RESTProxy configuration that autosyncs properly as nodes are added to the tree (using the NodeInterface.appendChild). If the server returns an "exception" because of a duplicate model id, the store still contains the rogue node. It seems that if the server returns success:false, then the node should not be added.

Additionally, this behavior results in 2 models in the same store with the same id. I am afraid that if I try to manually delete the unwanted node from the tree, autosync will delete the good node from the server. Please advise.


Here is my model:


Ext.define('NsgProjectManager.model.ProjectsNode', {
extend: 'Ext.data.Model',


hasMany: {
model: 'NsgProjectManager.model.ProjectsNode',
name: 'children'
},


fields: [
{
name: 'id'
},
{
name: 'type'
},
{
name: 'created'
},
{
name: 'label',
type: 'string'
},
{
name: 'associates',
type: 'string'
}
],


proxy: {
type: 'rest',
listeners: {
exception: {
fn: function(pxy, response, operation, options){
alert(response.toString());
}
}
},
url: 'rest',
reader: {
type: 'json'
},
writer: {
type: 'json',
getRecordData: function(record) {
return {
'id': record.data.id,
'type': record.data.type,
'created': record.data.created,
'label': record.data.label,
'associates': record.data.associates
};
}
}
}
});


Here is my store:


Ext.define('NsgProjectManager.store.ProjectsCollection', { extend: 'Ext.data.TreeStore',


requires: [
'NsgProjectManager.model.ProjectsNode'
],


constructor: function(cfg) {
var me = this;
cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: true,
autoSync: true,
storeId: 'MyJsonTreeStore',
model: 'NsgProjectManager.model.ProjectsNode',
defaultRootId: 'projects',
root: {
type: 'folder',
label: 'All Projects',
expanded: true
}
}, cfg)]);
}
});

mitchellsimoens
14 Dec 2012, 6:13 AM
You have data client side which is separate from the server. So if the sync is not successful then you need to remove it from the client.