PDA

View Full Version : Reader looks for 'children' root when updating TreeStore Model and receiving response



feiichi
6 Nov 2011, 10:51 AM
Hello.

I have a TreeStore with a Model defined. The Model uses JSON rest/ajax proxy. Now what I am trying to accomplish:

1. Read whole tree - OK:

[{text:"node1",children:[{text...}]}

2. Update a single record (Model) from the loaded TreeStore - OK:

record.set('text', 'xxx')

3. Save the record.

The record is sent to the server. It is a single resource modification so if everything goes ok, server returns the saved record serialized to JSON, again - single resource, not array:

{id:1,text:'xxx'...}

And the reader for the TreeStore Model tries to read the response. If the response were an array
[{id:1...}], there would be no problem. The reader would take that array and later on it would take the first item in the array - our serialized modified resource. But since the response is a single serialized resource, it tries to apply additional logic according to the "reader.root" config

src/data/reader/Reader.js, 305:

var root = Ext.isArray(data) ? data : me.getRoot(data)

I did not specified any root config for the TreeStore Model reader but since this is a TreeStore reader, the root config was given a value children by ext.

So the reader tries to getRoot, which is a regex processing function looking for the root element (children), which of course fails, so no records are returned to the model save operation callback and the javascript throws a null reference error in the model save function:

src/data/Model.js#save

record = operation.getRecords()[0];
me.set(record.data);

I don't think there is an easy fix for this, b/c it seems more like a conceptal error.

Thank you in advance for statement regarding this issue.

mitchellsimoens
17 Nov 2011, 1:45 PM
Can you please use the template (http://www.sencha.com/forum/showthread.php?138165-How-to-report-a-bug) or provide a runnable test case?