如何获取带有搜索字段的多列表以不显示引用的项目'版本和语言?

时间:2014-08-15 18:17:53

标签: sitecore sitecore7 sitecore7.2

我们正在使用Sitecore 7.2构建新的应用程序,并广泛使用新的Multilist with Search字段。我们希望能够在列表字段中关闭所列项目的版本和语言的显示。我们如何做到这一点?谢谢。

2 个答案:

答案 0 :(得分:4)

我认为您可以通过创建继承“Sitecore.Buckets.FieldTypes.BucketList”类的新字段类型来实现这一目标。

然后使用以下内容覆盖'OutputString'方法:

public override string OutputString(Item item4)
{
      Item parentBucketItemOrParent = item4.GetParentBucketItemOrParent();
      string str = (parentBucketItemOrParent != null) ? ("- " + parentBucketItemOrParent.get_Name()) : string.Empty;
      return string.Format("{0} ({1})", new object[] { item4.DisplayName, item4.TemplateName });
}

现在您需要将此字段类型添加到Sitecore,转到“Core”数据库,然后复制此项:

/ sitecore / system /字段类型/列表类型/带搜索的多列表

在新项目中,清除“控制”字段,并使用您的组件名称填写“汇编”,并使用[ Namespace.Classname ]填充“类”

希望这会有所帮助

修改

您可能还需要覆盖此函数,因为这会在您尝试搜索关键字时生成解析AJAX调用的JS函数:

    public override string JavaScriptOutputString(string clientId)
    {
        string[] strArrays = new string[] { "responseParsed", clientId, ".items[i].Name + ' (' + responseParsed", clientId, ".items[i].TemplateName + ')'" };
        return string.Concat(strArrays);
    }

答案 1 :(得分:1)

对于sitecore 8及以上版本,多列表字段的一部分由javascript文件的Ajax响应填充。

下面的行需要修改您的要求,即

  

websiteRoot / Sitecore的/壳/控制/ BucketList / BucketList.js

multilist.options[multilist.options.length] = new Option((item.DisplayName || item.Name) + ' (' + item.TemplateName + (item.Bucket && (' - ' + item.Bucket)) + ')', item.ItemId);

对于要显示的项目名称或显示名称,请执行以下操作:

multilist.options[multilist.options.length] = new Option((item.DisplayName || item.Name), item.ItemId);

确保在更改.js文件后清除浏览器缓存。