【发布时间】:2014-05-02 08:36:43
【问题描述】:
我有一个具有 DropList 字段的数据模板。我希望数据源来自两个 Sitecore 文件夹项。
是否可以为下拉列表定义多个来源?
【问题讨论】:
标签: c# asp.net .net content-management-system sitecore
我有一个具有 DropList 字段的数据模板。我希望数据源来自两个 Sitecore 文件夹项。
是否可以为下拉列表定义多个来源?
【问题讨论】:
标签: c# asp.net .net content-management-system sitecore
为什么不尝试使用 Sitecore Query 设置位置并使用 AND 拆分两个文件夹?
【讨论】:
不在标准下拉列表字段中,但根据从 source 字段获取 2 个参数的 Droplist 创建自定义站点核心字段应该不会太难。
这是创建自定义控件的好资源:http://sitecorejunkie.com/2012/12/28/have-a-field-day-with-custom-sitecore-fields/
下拉列表控件使用 Sitecore.Shell.Applications.ContentEditor.ValueLookupEx 作为其控件。因此,您可以创建一个继承自该控件的新控件并覆盖 GetItems() 方法以从源中读取项目
当前是这样的:
protected override Item[] GetItems(Item current)
{
Assert.ArgumentNotNull((object) current, "current");
using (new LanguageSwitcher(this.ItemLanguage))
return LookupSources.GetItems(current, this.Source);
}
所以你可以让源有 2 个由管道 (|) 分割的 guid/路径
protected virtual Item[] GetItems(Item current)
{
Assert.ArgumentNotNull((object) current, "current");
using (new LanguageSwitcher(this.ItemLanguage))
{
var sourceList = this.Source.Split('|');
var items = LookupSources.GetItems(current, source[0]).ToList();
items.AddRange(LookupSources.GetItems(current, source[1]));
return items.ToArray();
}
}
【讨论】: