【问题标题】:Getting children children in sitecore让孩子们进入 sitecore
【发布时间】:2012-11-22 14:10:05
【问题描述】:

我正在尝试在 Sitecore 的父页面上列出具有设置模板的项目。到目前为止,我可以为孩子们做这件事,但我也想包括孩子们的孩子,即父母下的任何东西,如果它有选择的模板,它将起作用,这是我在 c# 文件中的代码:

lvThing.DataSource = context.Children.Where(x => x.TemplateName == "cool    template").ToList<Item>();
lvThing.DataBind();

【问题讨论】:

    标签: c# asp.net sitecore


    【解决方案1】:

    如果你想要孩子下面的项目,你可以使用 item.Axes.GetDescendants() 方法来获取上下文项目下面的所有项目。

    您的代码应如下所示:

    contextItem.Axes.GetDescendants().Where(x => x.TemplateName == "cool    template").ToList();
    

    【讨论】:

    • 您好,感谢您的回复,但出现错误,使用:lvThing.DataSource = contextItem.Axes.GetDescendants().Where(x => x.TemplateName == "cool template").ToList ();
    • 啊,通过将 contextitem 更改为 context 来开始工作。感谢您的帮助:-)
    • 我会小心使用 GetDescendants,它可能非常昂贵。
    • 鉴于应用了额外的过滤,您可以考虑使用 contextItem.Axes.SelectItems(string query),它允许您使用相对于 contextItem 执行的站点核心查询。 (例如:contextItem.Axes.SelectItems("descendant-or-self::*[@@templatename='cool template']")
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-10
    • 1970-01-01
    • 1970-01-01
    • 2020-07-06
    • 2022-08-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多