2013-06-05 73 views
0

我用KendoUI樹形綁定到遠程數據, 下面是我的代碼:
如何在kendo.data.HierarchicalDataSource中獲取祖父的數據?

  <script> 
      var serviceRoot = "/kendoui"; 

      var Taxonomys = { 
       schema: { 
        model: { 
         id: "Name", 
         hasChildren: function() { 
          return false; 
         } 
        } 
       }, 
       transport: { 
        read: { 
         url: function (options) { 
          return kendo.format("http://localhost/MySite/MySiteService.svc/Organization/{1}/Project/{0}/Taxonomy?includeSchema=0", options.Name); 
         } 
        } 
       } 
      }; 

      var Projects = { 
       schema: { 
        model: { 
         id: "Name", 
         hasChildren: function() { 
          return true; 
         }, 
         children: Taxonomys 
        } 
       }, 
       transport: { 
        read: { 
         url: function (options) { 
          return kendo.format("http://localhost/MySite/MySiteService.svc/Organization/{0}/Project", options.Name); 
         } 
        } 
       } 
      }; 

      homogeneous = new kendo.data.HierarchicalDataSource({ 
       transport: { 
        read: { 
         url: "http://localhost/MySite/MySiteService.svc/Organization ", 
         dataType: "jsonp" 
        } 
       }, 
       schema: { 
        model: { 
         id: "Name", 
         hasChildren: function() { 
          return true; 
         }, 
         children: Projects 
        } 
       } 
      }); 

      $("#treeview").kendoTreeView({ 
       dataSource: homogeneous, 
       dataTextField: ["Name", "Name", "Name"] 
      }); 
     </script> 
在Taxonomys

,我需要組織名稱。

http://localhost/MySite/MySiteService.svc/Organization/{1}/Project/{0}/Taxonomy?includeSchema=0 

但「u​​rl:function(options){}」中的選項僅包含Projects的名稱。我如何獲得項目的家長姓名?

回答

0

給定樹中的一個節點,您應該使用parent方法來瀏覽樹。

例子。如果我們想獲得所選節點的祖父母,我們應該使用:

var select = treeview.select(); 
console.log("select", select); 
if (select.length) { 
    var parent = treeview.parent(select); 
    if (parent.length) { 
     console.log("parent", treeview.dataItem(parent)); 
     var grandparent = treeview.parent(parent); 
     if (grandparent.length) { 
      console.log("grandparent", treeview.dataItem(grandparent)); 
     } else { 
      console.log("has no grandfather") 
     } 
    } else { 
     console.log("has no father") 
    } 
} else { 
    console.log("select a node"); 
} 

正如你可以看到我在做驗證,以檢查是否有選擇的一個節點,它有一個父親,有祖父。

我還顯示該項目的數據。有了這個,你應該能夠獲得組織和項目,只要它們是模型的一部分。

+0

我該怎麼辦呢運輸:{ 讀:{ 網址:功能(選擇){ 回報kendo.format(「HTTP://localhost/MySite/MySiteService.svc/Organization/ {1} /項目/ {0}/Taxonomy?includeSchema = 0「,options.Name); } } } – user2454489

+0

問題是如何從被擴展的節點獲取信息? – OnaBai

+0

是的。綁定到遠程數據 – user2454489

相關問題