Sitecore SPEAK - 以编程方式设置搜索数据源根目录

Sitecore SPEAK - set searchdatasource root programmatically

本文关键字:设置 搜索 数据源 根目录 方式 编程 SPEAK Sitecore      更新时间:2023-09-26

我最近一直在玩SPEAK dialog。到目前为止,我喜欢它,但偶然发现了一个问题。我已经在 url 参数中使用了 itemID,我想在列表控件中显示此项的子项。

我的方法是创建一个SearchDataSource,并通过javascript设置字段"rootItemId"。这似乎行不通。有没有办法在PageCode中访问SearchDataSource的rootItemId?

我最近使用的另一种方法是在这里使用 Anders Laub 的 JSON 数据源控件。 http://laubplusco.net/creating-simple-sitecore-speak-json-datasource/。

然后,从 JavaScript PageCode 中,您可以执行 Ajax 调用并追加 JSON 结果项以填充列表控件,其中列表控件绑定到 JSON 数据源 Json 属性。

$.ajax({
                url: "/api/sitecore/RolePermissions/GetAllRoles",
                type: "POST",
                context: this,
                success: function (data) {
                    var json = jQuery.parseJSON(data);
                    for (var i = 0; i < json.length; i++) {
                        var obj = json[i];
                        this.JsonDS.add(obj);
                    }
                }
            });

我设法用查询来做到这一点。在页面代码中:

public class SelectTitle : PageCodeBase
    {
        //Fetches DataSource as rendering
        public Rendering DataSource { get; set; }
        public override void Initialize()
        {
            var articleid = WebUtil.GetQueryString("article");
            if (!String.IsNullOrEmpty(articleid))
            {
                //Set the query.
                this.DataSource.Parameters["query"] =
                    String.Format("fast:/some/path/*[@@id = '{0}']/Elements/*[@@templateid = '{1}']", articleid, '{guid}');
            }
        }
    }