问题描述
我试图弄清楚如何将 Droplink
链接到树列表
中的选定项目。
我有一个字段主题
,它是 Treelist
,一个字段 MasterTheme
,即 Droplink
。
I'm trying to figure out how I can link a Droplink
to the selected items in a Treelist
.I have a field Theme
, which is the Treelist
, and a field MasterTheme
, which is the Droplink
.
我应该能够在 Droplink
中选择一个主主题,其中填充了从中选择的数据树列表
。
I should be able to select a master-theme in the Droplink
, which is filled with the selected data from the Treelist
.
我对Sitecore来说还很陌生,而且我对自定义类也不熟悉。
I'm pretty new to Sitecore, and I'm not familiar with Custom classes.
推荐答案
为此,您可以使用 getLookupSourceItems
管道。使用 Droplink
,您可以将Sitecore查询指定为源。使用 getLookupSourceItems
,您可以在运行时更改源。以下处理器检查树列表
中选择的项目,并创建一个Sitecore查询,其中包括树列表
中选择的所有项目。
You can use the getLookupSourceItems
-pipeline for this. With a Droplink
you can specify a Sitecore query as source. And with the getLookupSourceItems
you can change the source at runtime. The following processor checks the items selected in the Treelist
and create a Sitecore query which includes all the items selected in the Treelist
.
public class LookupItemsFromField
{
private const string FromFieldParam = "fromfield";
public void Process(GetLookupSourceItemsArgs args)
{
// check if "fromfield" is available in the source
if (!args.Source.Contains(FromFieldParam))
{
return;
}
// get the field
var parameters = Sitecore.Web.WebUtil.ParseUrlParameters(args.Source);
var fieldName = parameters[FromFieldParam];
// set the source to a query with all items from the other field included
var items = args.Item[fieldName].Split('|');
args.Source = this.GetDataSource(items);
}
private string GetDataSource(IList<string> items)
{
if (!items.Any()) return string.Empty;
var query = items.Aggregate(string.Empty, (current, itemId) => current + string.Format(" or @@id='{0}'", itemId));
return string.Format("query://*[{0}]", query.Substring(" or ".Length));
}
}
您必须指定哪个字段是源 Droplink
源中的字段与 fromfield =< SourceField>
:
You have to specify which field is your "Source" field within the Droplink
source with fromfield=<SourceField>
:
在最后,您需要配置此管道处理器:
At the end you need to configure this pipeline processor:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<pipelines>
<getLookupSourceItems>
<processor patch:before="processor[1]"
type="Website.LookupItemsFromField, Website" />
</getLookupSourceItems>
</pipelines>
</sitecore>
</configuration>
这篇关于如何将Droplink链接到Sitecore中的树列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!