Results 1 to 4 of 4

Thread: TreeStore problems loading nested data from web service

  1. #1

    Default TreeStore problems loading nested data from web service

    I'm having trouble loading a TreeStore from nested data returned from a web service. None of the nodes get populated if the node data is contained in a top level property of the response object. There is no problem if the node data IS the response object. How can I get the following scenario to load a TreeStore properly?

    Using the TreeGrid example in the API docs, consider wrapping the existing TreeGrid.json content in the following structure:

    Code:
    {
        "context":"ABC",
        "success":true,
        "payload": <!-- TreeGrid.json content here -->,
        "elapsed":123
    }
    Again, using the TreeGrid example, I'm using the following definition for my TreeStore:

    Code:
    store = Ext.create('Ext.data.TreeStore', {
        model: 'Task',
        proxy: {
            type: 'ajax',
            //the store will get the content from the .json file
            url: 'treegrid.json',
            reader: {
                type: 'json',
                root: 'payload'
            }
        },
        folderSort: true
    });
    I'm guessing that once I set the reader's root it's looking for a "payload" property instead of "children" property to identify all child nodes. If so, does this mean we can't wrap TreeStore data in a response object that includes additional information about the request and can only return the tree itself? This is a big problem for me (and I assume many corporate users) as we have a standard payload wrapper that is used for json responses from every web service call.

    If I'm overlooking something here help would be appreciated.

  2. #2
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,199
    Answers
    87

    Default

    Yes, nested data is under the same property as the root.

  3. #3

    Default

    Thanks for the response tvanzoelen.

    So the Ext designers never considered a top level wrapper for tree/node data? Seems like a major oversight that will preclude many corporate developers from using the TreeStore with remote json services.

    There should be some type of json node reader for TreeStore that has not just a root property but also a nodeRoot property where root would be the location of the root node and the nodeRoot would be where the nodes are defined under the root node. The root property works as expected for tabular data with the Store.

  4. #4
    Sencha Premium Member
    Join Date
    Sep 2011
    Posts
    122

    Lightbulb

    This is a major flaw in my eyes! Most json responses (REST-proxies, Ajax-forms) require a "top-level-wrapper" around the actual data. Why should this be different when working with tree stores? If my top-level root-element is different than the "child-node" the tree store is unusable!

    Code:
    {
      "data": {
        "text": "foo",
        "children": [
          {
            "text": "baz",
            "children": []
          }, {
            "text": "bazbar",
            "children": []
          }
        ]
      },
      "message": "working",
      "success": true
    }
    This has to work!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •