我们在 sitecore 中有一个数据结构,它具有相同“深度”的相同模板。我们正在制作具有以下结构的单元、课程和活动的课堂内容:
Unit 1
-- Lesson 1
---- Activity 1
---- Activity 2
-- Lesson 2
---- Activity 3
---- Activity 4
Unit 2
-- Lesson 3
---- Activity 5
---- Activity 6
-- Lesson 4
---- Activity 7
---- Activity 8
等等。当我在一个activity
项目上时,我想返回该activity
特定项目中的下一个项目unit
,如果该单元中没有更多活动,则返回 null。
到目前为止,我能做的最好的事情是定位当前活动的unit
祖先(很容易找到)并获取activities
它下面的所有内容,然后遍历所有这些活动以获取上一个/下一个活动。似乎必须有更好的方法来实现这一点,所以我想我会把它扔在这里寻求想法。
当前代码
Item unit = Sitecore.Context.Item.Axes.SelectSingleItem("ancestor-or-self::*[@@templatename='Unit']");
Item[] allActivities = unit.Database.SelectItems("ancestor-or-self::*[@@templatename='Activity']");
foreach(Item thisitem in allActivities){
//Process here
}
Siblings ("Following" & "Preceeding") 不起作用,因为它只返回相同的直接兄弟姐妹lesson
,而不是unit
根据需要返回。