【问题标题】:Sitecore custom field treeview with multiselect具有多选功能的 Sitecore 自定义字段树视图
【发布时间】:2015-06-25 08:06:44
【问题描述】:

我创建了自定义树视图字段 - 多选树视图。

此字段继承自 Sitecore.Shell.Applications.ContentEditor.TreeList 并重写了 Add() 方法:

public class MultiselectTreeList : TreeList
{
    protected new virtual void Add()
    {
            bool alert = true;
            if (this.Disabled) return;
            string viewStateString = this.GetViewStateString("ID");
            var treeviewEx = this.FindControl(viewStateString + "_all") as TreeviewEx;
            Assert.IsNotNull(treeviewEx, typeof (DataTreeview));
            var listbox = this.FindControl(viewStateString + "_selected") as Listbox;
            Assert.IsNotNull(listbox, typeof (Listbox));
            if (treeviewEx == null)
            {
                SheerResponse.Alert("TreeviewEx control not found..", new string[0]);
            }
            else
            {
                Item[] selectionItems = treeviewEx.GetSelectedItems();
                if (selectionItems == null)
                {
                    SheerResponse.Alert("Select an item in the Content Tree.", new string[0]);
                }
                else
                {
                    foreach (Item selectionItem in selectionItems)
                    {
                        if (this.HasExcludeTemplateForSelection(selectionItem)) return;
                        if (this.IsDeniedMultipleSelection(selectionItem, listbox))
                        {
                            if (alert)
                            {
                                SheerResponse.Alert("You cannot select the same item twice.", new string[0]);
                                alert = false;
                            }
                        }
                        else
                        {
                            if (!this.HasIncludeTemplateForSelection(selectionItem)) return;
                            SheerResponse.Eval("scForm.browser.getControl('" + viewStateString +
                                               "_selected').selectedIndex=-1");
                            var listItem = new ListItem {ID = GetUniqueID("L")};
                            Sitecore.Context.ClientPage.AddControl(listbox, listItem);
                            listItem.Header = this.GetHeaderValue(selectionItem);
                            listItem.Value = listItem.ID + (object) "|" + selectionItem.ID;
                            SheerResponse.Refresh(listbox);
                            SetModified();
                        }
                    }
                }
            }
        }
}

我已经在核心数据库中注册了它:/sitecore/system/Field types/Custom Types/Multiselect Tree List:填充了Assembly和Class字段。

添加了带有多选树列表字段的项目。填充数据。多选工作正常。

但是当我尝试使用 Ribbon->Navigate->Links 查找引用时,我看不到对项目的引用(也错过了主数据库中 Links 表中的 TargetItemId)。

当我将其更改为 Sitecore Treeview 字段时 - 一切正常。

据我了解,爬虫不会索引我的字段和未添加到数据库的链接。

任何想法如何解决这个问题?

【问题讨论】:

    标签: treeview sitecore


    【解决方案1】:

    在 App_Config\FieldTypes.config 中注册您的字段类型。完成后,以后对该字段的写入将包含在 LinkDatabase 中。

    【讨论】:

    • 已注册 但不起作用。
    • 如果您切换到原始值,您能否看到存储在您的字段中的 ID 值?
    • 你是对的。但是您应该注册您的字段类型,而不是使用您的程序集和类型名称,而是使用 sitecore:
    • 好的,很高兴它成功了。诚然,自从我上次遇到这个问题以来已经有“一段时间”了;-) intothecore.cassidy.dk/2008/12/…
    【解决方案2】:

    尝试也将其添加到索引配置中:

    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:x="http://www.sitecore.net/xmlconfig/">
      <sitecore>
        <fieldTypes>
          <fieldType name="Multiselect Treelist" type="Sitecore.Data.Fields.MultilistField,Sitecore.Kernel" />
        </fieldTypes>
        <contentSearch>
          <indexConfigurations>
            <defaultLuceneIndexConfiguration>
              <fieldMap             type="Sitecore.ContentSearch.FieldMap, Sitecore.ContentSearch">
                <fieldTypes hint="raw:AddFieldByFieldTypeName">
                  <fieldType fieldTypeName="multiselect treelist"               storageType="NO" indexType="TOKENIZED" vectorType="NO" boost="1f" type="System.String"   settingType="Sitecore.ContentSearch.LuceneProvider.LuceneSearchFieldConfiguration, Sitecore.ContentSearch.LuceneProvider" />
                </fieldTypes>
              </fieldMap>
              <fieldReaders type="Sitecore.ContentSearch.FieldReaders.FieldReaderMap, Sitecore.ContentSearch">
                <mapFieldByTypeName>
                  <fieldReader fieldTypeName="multiselect treelist"  fieldNameFormat="{0}" fieldReaderType="Sitecore.ContentSearch.FieldReaders.MultiListFieldReader, Sitecore.ContentSearch" />
                </mapFieldByTypeName>
              </fieldReaders>
            </defaultLuceneIndexConfiguration>
          </indexConfigurations>
        </contentSearch>
      </sitecore>
    </configuration>
    

    【讨论】:

      猜你喜欢
      • 2016-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 2016-10-01
      • 2021-03-12
      相关资源
      最近更新 更多