【问题标题】:How to create a dynamic source for a multilist in Sitecore?如何在 Sitecore 中为多列表创建动态源?
【发布时间】:2013-05-02 19:26:41
【问题描述】:

我有以下内容树结构:

  • 首页
    • 产品
      • 产品A
      • 产品 B
    • 组织
      • 组织 1
      • 组织 2
        • 组织配置 X
        • 组织配置 Y

Organizations 下的每个 Organizations 都有一个名为“Associated Products”的字段,它是一个多列表。这告诉系统每个组织都有哪些产品。 Org Config 数据模板有一个名为“Selected Products”的字段。当我添加一个新的组织配置内容项(它始终位于组织的正下方)时,我希望能够限制在“选定产品”字段(这是一个多列表)中显示的项目,以仅显示以下产品已与父组织关联。我在想可能有一种方法可以用 Sitecore Query 做到这一点,但我想不通。有什么想法吗?

【问题讨论】:

    标签: sitecore sitecore6


    【解决方案1】:

    在 Sitecore 的帮助下,我想通了。基本上你必须创建一个继承自 MultilistEx 的自定义控件。然后您需要覆盖 DoRender() 事件。在调用 base.DoRender() 之前,您必须更改源 (this.Source) 以使用 Sitecore 查询。以前我试图在 OnLoad 事件中这样做。所以我的代码现在看起来像这样:

    public class CustomMultiList : MultilistEx
    {
      private void ExcludeItems()
      {
        ...custom code here that builds a list of Item IDs to exclude from the Multilist source...
        ...list should look like this "@@id != 'some guid' and @@id != 'some guid' and so forth...
        ...you could also build a list of item ids to include. Any Sitecore query will do...
        ...you can use this.ItemID to get a reference to the current item that is being edited in the Content Editor...
    
        this.Source = "query:" + this.Source + "/*[" + myListOfItemIdsToExclude + "]";
      }
    
      protected override void DoRender(output)
      {
        this.ExcludeItems();
        base.DoRender(output);
      }
    }
    

    【讨论】:

    【解决方案2】:

    【讨论】:

    • 不知道为什么你被否决了,这是实现它的好方法,而不会与其他 Sitecore 类型混淆......
    猜你喜欢
    • 2022-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-26
    • 1970-01-01
    • 2015-06-24
    • 1970-01-01
    相关资源
    最近更新 更多