Sharepoint:如何在交叉发布场景中的显示模板上显示 AppendOnlyHistory

Sharepoint: How to show AppendOnlyHistory on a display template in a cross-publishing scenario

我试图实现的总体要求是显示评论(在列表中逐项进行)。

我通过在列表上启用版本控制并添加一个选项 "Append Changes to Existing Text" 设置为 true 的文本字段来添加创作端的功能。 这确实允许我评论项目并按时间顺序显示它们,但仅限于创作方。 问题是 UI 部分将在另一个网站集上完成,我找不到直接的方法来获取所有评论。

到目前为止,我找到的每个资源都指向

 <SharePoint:AppendOnlyHistory runat="server" FieldName="YourCommentsFieldName" ControlMode="Display"/>

问题是,我不能(不知道如何)在显示模板中使用它。 到目前为止,我正在使用 REST API、通过

获取所有数据
        var siteUrl=_spPageContextInfo.webAbsoluteUrl.replace("publishing","authoring");
        $.ajax({
            url: siteUrl + "/_api/web/lists/getbytitle('" + listname + "')/items(" + id + ")",
            type: 'GET',
            async:false,
            headers: {"accept": "application/json;odata=verbose",},
            dataType: 'JSON',
            success: function(json) {
               console.log(json);
               //var obj = $.parseJSON(JSON.stringify(json.d.results));
               //alert(obj);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("error :"+XMLHttpRequest.responseText);
            }
        });

这给我的只是最新的评论。我需要一种简单的方法来控制整个线程。

我最终使用 javascript 对象模型来获得它们:

function GetComments(listname, itemId) {
    var siteUrl = _spPageContextInfo.webAbsoluteUrl.replace("publishing", "authoring");
    if ($(".comments-history").length) {
        $().SPServices({
            operation: "GetVersionCollection",
            async: false,
            webURL: siteUrl,
            strlistID: listname,
            strlistItemID: itemId,
            strFieldName: "Comments",
            completefunc: function (xData, Status) {

                $(xData.responseText).find("Version").each(function (data, i) {

                    var xmlComment = $(this)[0].outerHTML;
                    var arr = xmlComment.split(/comments|modified|editor/g);
                    var comment = arr[1].trim().substring(2, arr[1].length-2);
                    var dateSt = Date.parse((arr[2].substring(1, arr[2].length)).replace('/"', ''));
                    var user = getUsername(arr[3]);

                    var st = "<div class='comment-item'><div class='comment-user'>" + user + "(" + FormatDate(dateSt) + ")</div>";
                    st += "<div class='comment-text'>" + comment + "</div></div>";
                    $(".comments-history").append(st);
                });
            }
        });
    }
}

解析可能会更好,但这只是一个初步的工作想法