c# - 具有多个来源的 Sitecore 下拉列表

标签 c# asp.net .net content-management-system sitecore

我有一个包含 DropList 字段的数据模板。我希望数据源来自两个 Sitecore 文件夹项目。

有没有办法为下拉列表定义多个来源?

最佳答案

不在标准下拉列表字段中,但基于从 source 字段获取 2 个参数的 Droplist 创建自定义 sitecore 字段应该不会太难。

这是创建自定义控件的好资源: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 个 guids/路径,用竖线 (|) 分割

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();
  }
}
  • 免责声明 - 此代码未经测试,但应该为您指明正确的方向。

关于c# - 具有多个来源的 Sitecore 下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22618705/

相关文章:

c# - 从字符串中获取多个数字

c# - 从单词开头开始的子字符串

c# - 在 C# 中开发 HTTP 监视器

.net - 来自 bash,要学习什么 Windows 脚本语言?

c# - 链式方法

c# - 找不到 SqlConnection 命名空间

c# - 根据属性值复制部分 XML 文件

Javascript 无法在 IIS7.5 上的网站内运行 - Windows Server 2008 R2

javascript - window.opener 没有改变

ASP.NET CustomErrors - RemoteOnly 其中 "remote"表示在我们的网络之外