1

For loading a tree(full load, not lazy-load on expand), I need to make a request to a REST resource on the server. The issue is that the tree is hierarchical and in the REST philosophy I can only request one resource at a time.

How can I load the whole tree by following REST principles?

Thanks.

Dan L.
  • 1,717
  • 1
  • 21
  • 41
  • Just realize that all contents of a tree root ARE a single resource. – Mchl Jan 12 '11 at 22:50
  • I've read this comment: http://stackoverflow.com/questions/2654640/multiple-records-with-one-request-in-restful-system/2657230#2657230 and "There is a good reason for not returning multiple records in a single request, it's less cache-able and less scalable" – Dan L. Jan 12 '11 at 22:52

1 Answers1

1

You could make an Ajax call to populate an object with the full tree hierarchy, then reference that object in your tree config. Your REST web resource obviously needs to return a JSON object representing your tree in the correct format (example below).

//populate this with results from Ajax call
var rootNode = {
    text     : 'Root Node',
    expanded : true,
    children : [
        {
            text : 'Child 1',
            leaf : true
        },
        {
            text : 'Child 2',
            leaf : true
        },
        {
            text     : 'Child 3',
            children : [
                {
                    text     : 'Grand Child 1',
                    children : [
                        {
                            text : 'Etc',
                            leaf : true
                        }
                    ]
                }
            ]
        }
    ]
}

var tree = {
    xtype      : 'treepanel',
    id         : 'treepanel',
    autoScroll : true,
    root       : rootNode
}
James
  • 4,117
  • 2
  • 18
  • 13