Sitecore:按字段选择项目:TreelistEx

idm*_*idm 4 asp.net sitecore sitecore6

我有一个名为MyItems的Sitecore文件夹,其中包含MyItem类型的项目.我需要使用sitecore查询或使用xpath从.net代码查询项目.MyItem的字段为MyField,类型为TreelistEx.我需要选择MyField包含'thevalue'的所有项目(guid of other item).我该怎么做?

非常感谢

Bry*_*yan 5

string query = string.Format("/sitecore/content/MyItems/*[contains(@MyField,'{0}')]", thevalue);
Item[] myItems = Sitecore.Context.Database.SelectItems(query);
Run Code Online (Sandbox Code Playgroud)

我刚从我的网站上提取此代码并调整了查询​​的名称.如果你有很多MyItems,这是相当低效的,所以我不会在性能关键的页面上使用它.相同的查询应适用于任何列表类型字段.