对于加载树(完全加载,而不是扩展时的延迟加载),我需要向服务器上的REST资源发出请求。问题是树是分层的,在REST哲学中我一次只能请求一个资源。
如何按照REST原则加载整个树?
感谢。
答案 0 :(得分:1)
您可以进行Ajax调用以使用完整的树层次结构填充对象,然后在树配置中引用该对象。您的REST Web资源显然需要以正确的格式返回表示树的JSON对象(例如下面的例子)。
//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
}