代码之家  ›  专栏  ›  技术社区  ›  Thomas Seyssens

如何在Sitecore中将droplink链接到Treeist

  •  2
  • Thomas Seyssens  · 技术社区  · 11 年前

    我想知道我如何链接 Droplink Treelist . 我有一个领域 Theme ,这是 特雷利斯特 ,和一个字段 MasterTheme ,这是 下拉链接 .

    我应该能够在 下拉链接 ,其中填充了 特雷利斯特 .

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

    2 回复  |  直到 11 年前
        1
  •  10
  •   Ahmed Okour    11 年前

    您可以使用 getLookupSourceItems -这方面的管道。用一个 Droplink 可以将Sitecore查询指定为源。与 获取查找源项 您可以在运行时更改源代码。以下处理器检查 Treelist 并创建一个Sitecore查询,该查询包括 特雷利斯特 .

    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));
        }
    }
    

    您必须在 下拉链接 具有的源 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>
    
        2
  •  2
  •   RvanDalen    11 年前

    我想这就是你想要的: http://getfishtank.ca/blog/using-item-field-as-a-data-source-in-sitecore

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

    推荐文章