在数据绑定之前过滤掉 Sitecore 项目

发布于 2024-08-22 08:00:42 字数 916 浏览 3 评论 0原文

我想从 Sitecore.Data.Items 类型的列表中过滤/删除项目。 这就是我填写清单的方式。

List<Item> actueelItems = Sitecore.Context.Database.SelectItems("/sitecore/content/destil_nl/Home/").ToList();

我有一个方法可以检查项目是否有效。这将返回 true 或 false。 我想建立一个新列表,我将调用filteredList,其中仅包含有效项目。

实现这一目标的最佳方法是什么?

顺便说一句,这是我的验证方法:

public static bool ValidateItem(Item item)
    {
        return ValidateItem(item, true);
    }


public static bool ValidateItem(Item item, bool checkVisualization)
{
    bool result = true;
    if (item.Versions.Count <= 0 ||
        !item.Publishing.IsValid(DateTime.Today, false) ||
        (checkVisualization && item.Visualization.GetLayout(Sitecore.Context.Device) == null))
    {
        result = false;
    }

    return result;
}

目前我正在使用 itemDataBound 中的检查,但该项目仍然会显示,只是值错误。我想我必须过滤列表,并将过滤后的列表作为数据源。我只是不知道如何使用 ValidateItem 轻松过滤此列表。

I want to filter out / remove items from a list of type Sitecore.Data.Items.
This is how i fill the list.

List<Item> actueelItems = Sitecore.Context.Database.SelectItems("/sitecore/content/destil_nl/Home/").ToList();

I have a method that checks wheter an item is valid. This will return true or false.
I want to put up a new list, that i will call the filteredList with only the valid items in it.

What's the best way to achieve this?

This by the way is my validate method:

public static bool ValidateItem(Item item)
    {
        return ValidateItem(item, true);
    }


public static bool ValidateItem(Item item, bool checkVisualization)
{
    bool result = true;
    if (item.Versions.Count <= 0 ||
        !item.Publishing.IsValid(DateTime.Today, false) ||
        (checkVisualization && item.Visualization.GetLayout(Sitecore.Context.Device) == null))
    {
        result = false;
    }

    return result;
}

Currently i am using the check in the itemDataBound but then the item will still be shown, only with the wrong values. I figured i have to filter the list, and give the filtered list as datasource. I just don't know how i can easily filter this list using the ValidateItem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅听莫相离 2024-08-29 08:00:42

我已经解决了我自己的难题。
在我有列表的地方,我将只运行 linq .where 并验证我的项目:

actueelItems = actueelItems.Where(c => MenuItemHelper.ValidateItem(c, false)).ToList<Item>();

将来可能对其他人来说很方便!

I have solved my own puzzle.
Where i have the list, i will just run a linq .where and validate my items:

actueelItems = actueelItems.Where(c => MenuItemHelper.ValidateItem(c, false)).ToList<Item>();

Might be handy for someone else in the future!

ζ澈沫 2024-08-29 08:00:42

LINQ 加上扩展方法或包装类为查询和过滤 sitecore 项目提供了很多可能性。

LINQ plus extension methods or wrapper classes opens up a lot of possibilities for querying and filtering sitecore items.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文