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

ser*_*gio 9 display-templates sharepoint-2013

我试图实现的首要要求是显示注释(在列表中逐项进行).

我在创作方面添加了该功能,方法是在列表上启用版本控制,并添加一个文本字段,其中选项"将更改添加到现有文本"设置为true.这确实允许我对项目进行评论并按时间顺序显示它们,但仅限于创作方.问题是UI部分将在另一个网站集上完成,我找不到一种简单的方法来获取所有评论.

到目前为止,我发现的每一种资源都指向了

 <SharePoint:AppendOnlyHistory runat="server" FieldName="YourCommentsFieldName" ControlMode="Display"/>
Run Code Online (Sandbox Code Playgroud)

问题是,我不能(不知道如何)在显示模板中使用它.到目前为止,我通过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);
            }
        });
Run Code Online (Sandbox Code Playgroud)

这给我的是最新的评论.我需要一个简单的方法来获取整个线程.

ser*_*gio 0

我最终使用 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);
                });
            }
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

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