如何链接一个下拉链接到Sitecore中的Treelist

问题描述:

我想知道如何将Droplink链接到Treelist中的选定项目。 我有一个字段Theme,这是Treelist,和字段MasterTheme,这是Droplink如何链接一个下拉链接到Sitecore中的Treelist

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

我对Sitecore很陌生,对自定义类不熟悉。

您可以使用getLookupSourceItems -plineline。使用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)); 
    } 
} 

你指定哪个字段是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> 
+0

嘿,这真的有窍门!谢谢您的帮助! – 2014-09-11 11:53:41

我认为这是你在找什么:http://getfishtank.ca/blog/using-item-field-as-a-data-source-in-sitecore

基本上你就可以一个字段的数据源设置为另一个。