sitecore 的 treeviewex 如何与 javascript 相关联?

How does sitecore's treeviewex get associated with the javascripts?

我目前正在尝试在 sitecore 中创建一个与 treeviewex 非常相似的控件。

但我不清楚我将如何像 sitecore 那样包含 javascript。

如果有人能指出正确的方向,我将不胜感激,谢谢 :)

/罗宾

您可以创建自己的处理器并将其添加到 renderContentEditor 管道中。您可以在此博客 post 中找到有关 Adding custom Javascript and Stylesheets in the Content Editor

的信息和代码

创建一个新处理器class:

public class InjectScripts
{
    private const string JavascriptTag = "<script src=\"{0}\"></script>";
    private const string StylesheetLinkTag = "<link href=\"{0}\" rel=\"stylesheet\" />";

    public void Process(PipelineArgs args)
    {
        AddControls(JavascriptTag, "CustomContentEditorJavascript");
        AddControls(StylesheetLinkTag, "CustomContentEditorStylesheets");
    }

    private void AddControls(string resourceTag, string configKey)
    {
        Assert.IsNotNullOrEmpty(configKey, "Content Editor resource config key cannot be null");

        string resources = Sitecore.Configuration.Settings.GetSetting(configKey);

        if (String.IsNullOrEmpty(resources))
            return;

        foreach (var resource in resources.Split('|'))
        {
            Sitecore.Context.Page.Page.Header.Controls.Add((Control)new LiteralControl(resourceTag.FormatWith(resource)));
        }
    }
}

然后在处理器中打补丁:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
   <sitecore>
     <pipelines>
       <renderContentEditor>
         <processor patch:before="*[1]" type="HideDependentFields.SC.Pipelines.RenderContentEditor.InjectScripts, HideDependentFields.Types" />
       </renderContentEditor>
     </pipelines>
   </sitecore>
</configuration>