如何在Sitecore内容编辑器中选择项目

时间:2013-03-13 12:36:00

标签: sitecore

我有一个Sheer UI向导,它从用户收集信息,然后在sitecore中创建一个内容项。使用命令模板启动向导。

我希望向导将新创建的内容项目作为内容编辑器中当前选定的项目,但我无法确定如何执行此操作。有谁知道这是怎么做的?

更新

Trayek的建议让我更进一步。我现在在用于启动向导的命令中获得以下代码:

[Serializable]
public class MyNewContentCommand : Command
{

    public override void Execute(CommandContext context)
    {
        ClientPipelineArgs args = new ClientPipelineArgs();
        args.Parameters["id"] = context.Parameters["id"];
        Context.ClientPage.Start(this, "Run", args);
    }

    protected void Run(ClientPipelineArgs args)
    {
        if (!args.IsPostBack)
        {
            // This runs when the users clicks to add the item
            // in the content editor. 

            // Launches a modal wizard to collect user data

            string id = args.Parameters["id"];

            string controlUrl = Sitecore.UIUtil.GetUri("control:MyNewItemWizard");
            UrlString urlStr = new UrlString(controlUrl);
            urlStr.Append("id", id);

            SheerResponse.ShowModalDialog(urlStr.ToString(), true);
            args.WaitForPostBack();

        }
        else if (args.HasResult)
        {
            // This runs once the wizard has finished

            // Wizard passes ID of created item in its result
            // This is used to find the newly created item.
            Item created = Client.GetItemNotNull(ID.Parse(args.Result));

            // Sending these messages result in refreshing the child items
            // of the parent. And they work.
            Context.ClientPage.SendMessage(this, string.Format("item:updated(id={0})", created.Parent.ID));
            Context.ClientPage.SendMessage(this, string.Format("item:refreshchildren(id={0})", created.Parent.ID));

            // This message should select the new item in content editor, but
            // it doesn't have the desired effect.
            Context.ClientPage.SendMessage(this, string.Format("item:load(id={0})", (object)created.ID));
        }
    }
}

2 个答案:

答案 0 :(得分:2)

阅读this链接。它为您提供了3个选项:

  • 生成一个URL并链接到它
  • 从XAML应用程序中打开它
  • 从JavaScript打开

答案 1 :(得分:1)

很抱歉回答我自己的问题。导致该问题的原因是“内容树中的刷新项目”命令和“在内容树中选择项目”命令之间似乎存在竞争条件。我必须将select命令延迟几毫秒才能使它工作。

Context.ClientPage.SendMessage(this, 
    string.Format("item:updated(id={0})", created.Parent.ID));
Context.ClientPage.SendMessage(this, 
    string.Format("item:refreshchildren(id={0})", created.Parent.ID));
Context.ClientPage.ClientResponse.Timer(
    string.Format("item:load(id={0})", created.ID), 100);