2011-01-12 37 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 
}