1. #1
    Sencha Premium Member
    Join Date
    Jun 2012
    Posts
    117
    Answers
    6
    Vote Rating
    6
    benjamineberle is on a distinguished road

      0  

    Default Answered: Serialize tree

    Answered: Serialize tree


    What is the recommended way to serialize a tree respectively treestore into json, so one can save the whole tree at once in localstorage, for example?

    I guess the resulting json should look like this to be able to re-use it directly:
    Code:
    root: {text: 'root', children: [
        {text: 'leaf1'},
        {text: 'leaf2', children: [
            {},
            {}, ...
        ]}
    ]
    This might seem obvious, but I can't find the answer from the docs or previous posts. Isn't there anything built-in? I have created my own iteration function, but I can't imagine such a common task has to be re-built every time someone needs that...?

    Thanks!

  2. Hopefully, tree nodes will get the serialize method in 4.2

    I have added it, just needs review and QA

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,620
    Answers
    3452
    Vote Rating
    817
    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


    You can use the cascade method to work through the tree.
    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.

  4. #3
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,496
    Answers
    13
    Vote Rating
    44
    Animal has a spectacular aura about Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Hopefully, tree nodes will get the serialize method in 4.2

    I have added it, just needs review and QA

  5. #4
    Sencha - Support Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    4,800
    Answers
    359
    Vote Rating
    167
    slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold

      0  

    Default


    Nice, Animal!