PDA

View Full Version : Ext.tree.Panel writeAllFields not working



thhuebner
10 Jun 2013, 4:43 AM
Hi, I'm trying to send the complete tree to the server using the following store:


store : {
autoSync : true,
autoLoad : true,


id: 'store',


proxy: {
type: 'ajax',


url : '/services/chapters',


reader: {
root: 'items',
type: 'json'
},
writer: {
type: 'json',
root: 'items',
allowSingle: false,
writeAllFields: true,
encode: true
}
},
defaultRootProperty: 'items'
}


Despite of defining writeAllFields in the writer, when I change the tree data only the change is posted to the server:


[{"name":"Changed node...","id":12,"parentId":1,"leaf":true}]

Is it a bug or do I miss something here?

Farish
10 Jun 2013, 5:42 AM
writeAllFields refers to the fields in your model. i.e. it will send all fields of the record which has been modified and not all records. by default, it is true already.

what you can try is to set all the records to dirty yourself before sync().

thhuebner
10 Jun 2013, 11:35 PM
Ok so my understanding of this function was wrong. I'm using now this



rootNode = store.getRootNode();
rootNode.cascadeBy(function(n) {
n.setDirty();
});

to set all tree nodes to a dirty state. The writer retrieves all nodes but they are not in hierarchical order, how can I achieve that?

Current JSON writer output:



[{"name":"Parent","id":"root","parentId":null,"leaf":false},{"name":"Child1","id":1,"parentId":"root","leaf":true}]


I would need something like that:



[{ "name": "Parent", "id": "root", "items": [ { "name": "Child1", "id": 1, "leaf":true } ]}]


This way I can just save the JSON on the server and send it back for read requests.

Farish
11 Jun 2013, 12:23 AM
I am not sure if there is a direct way to do that. You might have to handle it on your backend by parsing all nodes and recreating the tree structure based on id or some other field. You can start another thread for it and see if someone else has better suggestions.