0

我需要帮助来使用HTML页面提取共享点公告列表。我已经尝试了来自各个站点的大量示例,但似乎根本没有任何效果。所以我显然是一无所知或不明白的东西....

将拉取共享点公告列表的 HTML 页面将位于 [http://mysite/Announce.html]

Sharepoint 站点位于 [http://companyweb/Lists/Announcements/AllItems.aspx]

我想让 html 页面(Announce.html)简单地列出公告的DateTitleBody

我知道有 jquery 方法等......但我似乎无法弄清楚这一点。

任何帮助将不胜感激。我是一个新手程序员,所以任何详细的例子都会很棒。

这是我迄今为止尝试过的,没有任何显示

测试.html

<script type="text/javascript" src="filelink/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="filelink/jquery.SPServices-0.5.4.min.js"></script>
<script language="javascript" type="text/javascript">

$(document).ready(function() {
  $().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "Announcements",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
    completefunc: function (xData, Status) {
      $(xData.responseXML).find("[nodeName='z:row']").each(function() {
        var liHtml = "<li>" + $(this).attr("ows_Title") + "</li>";
        $("#tasksUL").append(liHtml);
      });
    }
  });
});
</script>
<ul id="tasksUL"/>
4

2 回答 2

1

我为 Sharepoint 创建了一个 JS 库:http: //aymkdn.github.io/SharepointPlus/

这可能更容易使用(示例未测试):

<script type="text/javascript" src="filelink/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="filelink/sharepointplus-3.0.4.min.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
  $SP().list("Announcements").get({fields:"Title,Body,Created",orderby:"Created DESC"}, function(data) {
    var html="",d;
    for (var i=data.length; i--;) {
      d = $SP().toDate(data[i].getAttribute("Created")); // convert the Created date to a Javascript Date Object
      d = (d.getMonth()+1) + '/' + d.getDate() + '/' + d.getFullYear();
      html += "<li>" + data[i].getAttribute("Title") + " (" + d + ")</li>";
    }
    $("#tasksUL").append(html);
  })
})
</script>
于 2013-05-19T09:49:53.187 回答
0

这是我用来使用脚本从 SP 列表中检索数据的代码,我在 2010 和 2013 版本上使用过它,并且一直为我工作。

将您的 Sharepoint URL 设置为 SPURL,并更改网页

var SPURL="https://www.yoururl.com"
$(document).ready(function() {
    var soapEnv =
        "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
            <soapenv:Body> \
                 <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                    <listName>Web Pages</listName> \
                    <viewFields> \
                        <ViewFields> \
                           <FieldRef Name='Title' /> \
                       </ViewFields> \
                    </viewFields> \
                </GetListItems> \
            </soapenv:Body> \
        </soapenv:Envelope>";

    $.ajax({
        url: SPURL+"/_vti_bin/lists.asmx",
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        complete: processResult,
        contentType: "text/xml; charset=\"utf-8\""
    });
});

var names = new Array();
var href = new Array();
var iterator;

function processResult(xData, status) {
    $(xData.responseXML).find("z\\:row, row").each(function() {

    names.push($(this).attr('ows_Title'));
    href.push($(this).attr('ows_FileRef'));

    });
    var sorted = new Array();                                   
    for (var i=0; i<href.length; i++)
    {
         sorted.push([names[i],href[i]]); 
    }

    sorted=sorted.sort();
    iterator=href.length;
    var liHtml = "";
    for (var i=0; i<iterator; i++)
    {
        var name = sorted[i];
        var hrf = sorted[i]
        names[i]=(name[0].split("-"))[1];
        href[i]=(hrf[1].split("/"))[1];

        liHtml += "<li class='static'>" +
                "<a class='static menu-item' accesskey='1' href='"+href[i]+"'>" +
                "<span class='additional-background'>" +
                    "<span class='menu-item-text'>"+names[i]+"</span>" +
                "</span>" +
                "</a>" +
                "</li>";        
    }

    $("#SPData").append(liHtml);

}
于 2013-05-18T11:27:10.513 回答