RESTful way to load an extJS tree
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.
开发者_C百科How can I load the whole tree by following REST principles?
Thanks.
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
}
精彩评论