2016-08-12 32 views
9

我試圖實現的首要要求是顯示註釋(在列表中逐項顯示)。Sharepoint:如何在交叉發佈場景中的顯示模板上顯示AppendOnlyHistory

我在創作端添加了該功能,方法是在列表中啓用版本控制,並將選項「追加對現有文本的更改」設置爲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); 
      } 
     }); 

什麼這給了我只是最新的評論。我需要一個簡單的方法來抓住整個線程。

回答

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); 
       }); 
      } 
     }); 
    } 
} 

解析可能會更好,但是這只是一個初始的工作思路