如何在Sitecore中为多列表创建动态源?

时间:2013-05-02 19:26:41

标签: sitecore sitecore6

我有以下内容树结构:

  • 主页
    • 产品
      • 产品A
      • 产品B
    • 组织
      • Org 1
      • 组织2
        • Org Config X
        • Org Config Y

组织下的每个组织都有一个名为“关联产品”的字段,这是一个多列表。这告诉系统哪些产品与每个组织一起使用。 Org Config数据模板有一个名为“Selected Products”的字段。当我添加一个新的Org Config内容项(它总是直接位于组织下面)时,我希望能够限制“Selected Products”字段(这是一个多列表)中显示的项目,以便只显示已经与父组织相关联。我想可能有一种方法可以使用Sitecore Query来做到这一点,但我无法弄明白。有什么想法吗?

2 个答案:

答案 0 :(得分:2)

在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);
  }
}

答案 1 :(得分:1)

相关问题