如何在HTML页面中检索sharepoint公告列表

时间:2013-05-17 17:18:38

标签: javascript jquery html sharepoint

我需要帮助,使用 HTML 页面提取sharepoint公告列表。我已尝试过各种网站的大量示例,但似乎都没有。所以我显然无能为力或不理解......

将提取sharepoint公告列表的HTML页面将驻留在     的 [HTTP://mysite/Announce.html]

Sharepoint网站位于     的 [HTTP://companyweb/Lists/Announcements/AllItems.aspx]

我想让html页面( Announce.html )只列出日期标题公告的正文

我知道有jquery方法等等......但我似乎无法解决这个问题。

非常感谢任何帮助。我是一名新手程序员,所以任何详细的例子都会很棒。

这是我到目前为止所尝试过的,没有任何显示

的test.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"/>

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

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

在SPURL设置您的Sharepoint网址,然后更改网页

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

}