在数据绑定之前过滤掉 Sitecore 项目
我想从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经解决了我自己的难题。
在我有列表的地方,我将只运行 linq .where 并验证我的项目:
将来可能对其他人来说很方便!
I have solved my own puzzle.
Where i have the list, i will just run a linq .where and validate my items:
Might be handy for someone else in the future!
LINQ 加上扩展方法或包装类为查询和过滤 sitecore 项目提供了很多可能性。
LINQ plus extension methods or wrapper classes opens up a lot of possibilities for querying and filtering sitecore items.