PDA

View Full Version : Raw data from reader on nested json data



bminano
20 Nov 2014, 6:52 AM
Hi,

I have a problem reading json data form a TreeStore.
I have the following Model defined:


Ext.define('TreeModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'tag', type: 'string'},
{name: 'input', type: 'string'},
{name: 'type', type: 'string'},
{name: 'actionCol', type: 'string', defaultValue: true}
]
});

And its respective store:


var store = Ext.create('Ext.data.TreeStore', {
model: 'TreeModel',
proxy: {
type: 'ajax',
url: 'editorConverter/Collective_motion_problem.json',
reader: 'json'
},
folderSort: false
});

The problem comes when I try to get raw data from the reader with store.getProxy().getReader().rawData. The resulting json is only the root element and its immediate children, but no more descendant levels.

My Json file contains:

{"text":".","children": [ {"tag":"problem", "input": "none", "actionCol": "none", "expanded": false, "children":[
{"tag":"head", "input": "none", "actionCol": "none", "expanded": false, "children":[
{"tag":"name", "input": "Collective motion problem", "type": "string", "actionCol": "none"},
{"tag":"nameAbbreviation", "input": "none", "type": "string", "actionCol": "none"},
{"tag":"id", "input": "0100007f03297c2a0000013f7a85b63e", "type": "string", "actionCol": "none"},
{"tag":"author", "input": "Perico", "type": "string", "actionCol": "none"},
{"tag":"version", "input": "1", "type": "string", "actionCol": "none"}
]}
]}
]}

But I only get:

{"text":".","children": [ {"tag":"problem", "input": "none", "actionCol": "none", "expanded": false} ]}

I have a Tree panel where the content shown is complete. So the problem might not be in the store itself, but some configuration I am missing.

Can anybody help me?

joel.watson
20 Nov 2014, 6:52 PM
Sorry, I'm not able to replicate the issue you're experiencing. When are you calling this method? Have you ensured that the store has loaded?

Can you fork the fiddle I've linked below and tweak it so that it produces the issue? I'll be happy to help test it with you.

https://fiddle.sencha.com/#fiddle/do9

Thanks!

bminano
21 Nov 2014, 1:46 AM
Hi Joel,

Thanks for your interest. When I saw the fiddle working I couldn't believe it. It was not much different from what I'm doing, but now I see the problem.
I am using framework 4.2, and the fiddle default is 5, if you change it to 4.2 the raw data obtained is only the first level information, the root and child, but no other descendant.

Now my question is if it is a misconfiguration in 4.2 source code or a feature that can only be used with Ext JS 5.

Regards,

joel.watson
21 Nov 2014, 2:42 PM
Which version of 4.2 are you using? The fiddle I added defaults to 4.2.3.

bminano
23 Nov 2014, 11:47 PM
It's 4.2.1.883, which is already available in fiddle.

If you could try it, you'll see the problem I have, cause it's just what happens to me.

joel.watson
24 Nov 2014, 11:56 AM
It's 4.2.1.883, which is already available in fiddle.

If you could try it, you'll see the problem I have, cause it's just what happens to me.

Yes, I see what you're saying in 4.2.1. Can you describe what you're using this data for? We might be able to find a different approach to accomplish the same goal.

Thanks!

bminano
24 Nov 2014, 11:36 PM
Yes, I see what you're saying in 4.2.1. Can you describe what you're using this data for? We might be able to find a different approach to accomplish the same goal.

Thanks!

Sure.
My intention is to get the JSON data from the TreeStore in order to represent it in HTML using a Pure (beebole) directive. The parameter for this directive must be JSON data.
Maybe there is another way to get this JSON data, maybe JSON reader?

I am new to ExtJS, so maybe another approach is more convenient.

joel.watson
25 Nov 2014, 3:06 PM
One approach would be to simply recurse down the hierarchy and build out the structure you need. If you want to be a bit more exotic, you could create your own reader (http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.reader.Json) that does some magic in getResponseData() to preserve the data from the response that you want to use later.

Hope that helps!

bminano
25 Nov 2014, 11:44 PM
OK, then I assume that is not possible to get the data as I like directly from extJS classes in 4.2, but now it is implemented in 5.

I'll take your advise and create the JSON manually using NodeInterface. The only question I care about is the performance of doing this, since I use it to represent a TreeStore that could be modified and then represented.

joel.watson
26 Nov 2014, 6:33 AM
To be clear, it is working as you want in 4.2.3, so if you can do the dot update, it should work with that.

joel.watson
26 Nov 2014, 6:34 AM
And regarding performance, there might be a slight cost, but it shouldn't be too bad. If it is bad, the custom reader approach would be much more performant.

bminano
26 Nov 2014, 7:10 AM
Ok, then 4.2.3 also works as I expect. I will think on move.
But at the moment I have solved the problem with your suggestion.

Thank you very much.