2011-01-12 54 views
1

对于加载树(满载,而不是展开时的延迟加载),我需要向服务器上的REST资源发出请求。问题是树是分层的,在REST理念中,我一次只能请求一个资源。加载extJS树的RESTful方式

如何根据REST原则加载整棵树?

感谢。

+0

只要认识到树根的所有内容都是单一资源。 – Mchl 2011-01-12 22:50:36

回答

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 
}