2017-02-02 43 views
1

的我申請一個數據源到sublayout並獲得如下其孩子的價值觀:Sitecore的兒童數據源

Sitecore.Collections.ChildList childItems; 

if (Sitecore.Context.Database.GetItem(this.DataSource) != null) 
{ 
    childItems = Sitecore.Context.Database.GetItem(this.DataSource).GetChildren(); 
} 
else 
{ 
    litDataSourceError.Text += "You need to set a datasource"; 
} 

foreach (Item item in childItems) 
{ 
    litDataSourceError.Text += "<h2>" + item.Fields["Title"].Value + "</h2>"; 
} 

這是預期但這些項目也有孩子,我想輸出工作。

所以我的問題是如何在我的ForEach內部查看更多的節點來獲得兒童兒童 - 只會有這兩個層次的結構。

回答

1

你也應該這樣做,你做你的數據源(獲取Sitecore的項目的子女):

foreach (Item item in childItems) 
{ 
    litDataSourceError.Text += "<h2>" + item.Fields["Title"].Value + "</h2>"; 
    foreach (Item child in item.GetChildren()) 
    { 
     ... 
    } 
} 
+0

是有道理謝謝你的建議,我會採取這種做法。 – user3779703