如何将droplink链接到Sitecore中的Treelist

时间:2014-09-11 09:42:33

标签: sitecore datasource sitecore7 treelist

我正在试图找出如何将DroplinkTreelist中的所选项目相关联。 我有一个字段Theme,即Treelist,还有一个字段MasterTheme,即Droplink

我应该能够在Droplink中选择一个主主题,其中填充了Treelist中的所选数据。

我是Sitecore的新手,我不熟悉Custom类。

2 个答案:

答案 0 :(得分:10)

您可以使用getLookupSourceItems - 管道。使用Droplink,您可以将Sitecore查询指定为源。使用getLookupSourceItems,您可以在运行时更改源。以下处理器检查Treelist中选择的项目并创建Sitecore查询,其中包含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));
    }
}

您必须指定哪个字段是您的&#34;来源&#34; Droplink来源fromfield=<SourceField>内的字段:

enter image description here

最后,您需要配置此管道处理器:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <getLookupSourceItems>
        <processor  patch:before="processor[1]"
                    type="Website.LookupItemsFromField, Website" />
      </getLookupSourceItems>
    </pipelines>
  </sitecore>
</configuration>

答案 1 :(得分:2)

我认为这正是您所寻找的:http://getfishtank.ca/blog/using-item-field-as-a-data-source-in-sitecore

基本上,您可以将一个字段的数据源设置为另一个字段。