Hybrid View

  1. #1
    Sencha Premium Member
    Join Date
    Mar 2011
    Posts
    54
    Vote Rating
    1
    maikhorma is on a distinguished road

      0  

    Default TreePanel store reading different json format (4.0.7)

    TreePanel store reading different json format (4.0.7)


    Hi, currently I'm using XStream to convert Java objects into JSON, and it works fine for grids and everything else. The problem with using a treestore is that XStream's format (example 1) doesn't match ExtJs' (example 2) exactly. What is the best way to either tell the treestore how to read the different format, or at least reformat the json data as it comes during load()?

    I can get closer if i fudge example 1 by changing the top name to "children" and having the root defined as '["children"]["NodeType"]' but it looks like it breaks when it gets to the final leaf with "Cannot read property 'NodeType' of undefined".

    Thoughts?

    Example 1: XStreams result, it wants to preface the array with the type of objects it holds, so if i send the data back it knows how to deserialize it.
    PHP Code:
    {
        
    "data": {
            
    "NodeType": {
                
    "text""1-1",
                
    "leaf"false,
                
    "children": {
                    
    "NodeType": [
                        {
                            
    "text""1-0",
                            
    "leaf"false,
                            
    "children": {
                                
    "NodeType": [
                                    {
                                        
    "text""1-0-0",
                                        
    "leaf"true
                                    
    }
                                ]
                            }
                        }
                    ]
                }
            }
        }

    Example 2: Works with ExtJs 4
    PHP Code:
    {
        
    "children": [
            {
                
    "text""1-1",
                
    "leaf"false,
                
    "children": [ 
                    {
                        
    "text""1-0",
                        
    "leaf"false,
                        
    "children": [
                            {
                                
    "text""1-0-0",
                                
    "leaf"true
                            
    }
                        ]
                    }
                ]
            }
        ]

    Thanks in advance.

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,647
    Vote Rating
    899
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    It should place the NodeType key in there.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha Premium Member
    Join Date
    Mar 2011
    Posts
    54
    Vote Rating
    1
    maikhorma is on a distinguished road

      0  

    Default


    Sorry, you are right, that isn't the exact xstream output, i had been messing with it for a while to see what would work and left it that way for demonstration purposes. Normally it produces "children": "". It does that with null or an empty arraylist as the contents of the attribute. This still causes the same problem though because it would try and access the NodeType object of children which doesn't exist. I tried injecting an empty object to satisfy that, but then it seemed like it failed trying to turn the empty object into children.
    Last edited by maikhorma; 28 Feb 2012 at 6:41 PM. Reason: Cleaned up nbsp's caused by storing my message over a login due to timeout

Thread Participants: 1