Sitecore如何在数据源中显示项目的字段而不是项目名称

Kam*_*ran 1 sitecore sitecore7

在templateItem中,我有一个字段的以下信息.

Name : Product type
field type : 'Droplink' 
DataSource : DataSource=/sitecore/content/Enumerations/Products/Product type/
Run Code Online (Sandbox Code Playgroud)

当内容编辑器基于上面的模板创建项目时,对于Product type下拉列表中的字段' ',他将看到下面的项目../Product type.我的问题是在下拉列表中显示的项目如何显示其他字段而不是项目名称

jam*_*kam 5

这个功能并不是开箱即用的,虽然DropLink字段的代码看起来像有代码可以做到这一点(看一下GetItemHeader()方法Sitecore.Shell.Applications.ContentEditor.LookupEx),我不知道如何利用参数通过内容编辑器虽然......

尽管创建一个自定义字段来实现这一点很简单:

using Sitecore;
using Sitecore.Data.Items;
using Sitecore.Shell.Applications.ContentEditor;

namespace MyProject.Custom.Fields
{
    public class CustomDropLink : LookupEx
    {
        protected override string GetItemHeader(Item item)
        {
            if (string.IsNullOrEmpty(this.FieldName))
                this.FieldName = StringUtil.ExtractParameter("FieldName", this.Source).Trim();

            return base.GetItemHeader(item);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

然后在core数据库中注册您的自定义类/sitecore/system/Field types/.您可以通过复制/sitecore/system/Field types/Link Types/Droplink和设置以下值来执行此操作:

Assembly: MyProject.Custom
Class: MyProject.Custom.Fields.CustomDropLink
Control: <set this to empty>
Run Code Online (Sandbox Code Playgroud)

然后,当您使用此字段时,设置您的字段的来源,如下所示:

Datasource=/sitecore/content/path/to/items&FieldName=Title