Skip to main content
 首页 » 编程设计

用于从作者定义的文件夹结构中选择链接的 Sitecore 字段

2025年01月19日83xxx_UU

在 Sitecore 6.6 版本上工作,我允许作者创建具有以下结构的项目:

  • AAA
    • BBB
      • CCC
      • CCC
    • BBB
      • CCC
    • CCC

这里AAA、BBB、CCC是不同的模板。请注意,AAA 允许 BBB 或 CCC 项目,而 BBB 只允许 CCC。

我现在需要模板上的链接字段,源根设置为 AAA,其中作者只能选择模板 CCC 的单个项目。但至关重要的是,我希望在视觉上保留“文件夹”结构(由 BBB 定义)。

我无法使用 DropLink,因为项目列表已扁平化。

据我所知,我不能使用 DropTree,因为我无法阻止作者选择 BBB 类型的项目。

如果我提供多选,我可以使用带有数据源的 TreeList 并使用其参数(ExcludeTemplatesForSelection 等)。但我只想选择一个项目。

看起来 Grouped DropLink 正是我正在寻找的东西,但它似乎有问题。我可能会误解,所以非常感谢您的指导。下面的查询对我来说看起来是正确的,但提供了一个奇怪的选项列表,其中 BBB 的某些项目是可选的。

query:/sitecore/content/home/AAA//*[@@templateid='{CCC}'] 

非常感谢您的帮助。

请您参考如下方法:

我会按照您的建议选择 Treelist(甚至 TreelistEx),但在指定字段只能包含 1 个 guid 的字段上使用自定义验证器。将错误级别设置得足够高,以便非管理员用户在字段值错误时无法保存项目。 FatalError 将是您最好的选择。

ValidatorResult.CriticalError   // The validator resulted in a critical error. The user will be warned before saving. 
ValidatorResult.Error           // The validator resulted in an error. 
ValidatorResult.FatalError      // The validator resulted in a fatal error. The user cannot save before the error has been resolved. 
ValidatorResult.Suggestion      // The validator resulted in a suggestion. 
ValidatorResult.Unknown         // The validator has not yet evaluated. 
ValidatorResult.Valid           // The validator has evaluated and is valid. 
ValidatorResult.Warning         // The validator resulted in a warning.