利用SPServices制作纯静态sharepoint页面

SPServices非常强大,利用SPservices,一个纯静态的页面都可以呈现Sharepoint网站所有信息。

以下例子仅供参考:

1、取得某个网站某张列表下信息

//判断是否是新信息

function IsNew(created) {

    var today = new Date();

    created = created.substring(0, 10).replace("-", "/");

    var a = (Date.parse(today) - Date.parse(created)) / (24 * 3600 * 1000);

    //和当前时间比较差距在2填以内的为新信息

    if (a <= 2) {

        return true;

    }

    else {

        return false;



    }

}





//截取字符,超出的补...

function GetChars(title,num) {

    if (title.length > num) {

        title = title.substring(0, num - 1) + "...";

    }

    return title;

}





//------获取某个网站下某个列表信息开始--------

function GetListItems(weburl,listname,listurl,num,tlength,ulname)

   {

          $().SPServices({

            operation: "GetListItems",

            async: false,

            webURL: weburl,

            listName: listname,

            CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='Created' /></ViewFields>",

            CAMLQuery: "<Query><OrderBy><FieldRef Name='Created' Ascending='FALSE'></FieldRef></OrderBy></Query>",

            CAMLRowLimit: num,

            completefunc: function(xData, Status) {

            $(xData.responseXML).SPFilterNode("z:row").each(function() {

                    var id = $(this).attr("ows_ID");

                    var title=$(this).attr("ows_Title");

                    var created=$(this).attr("ows_Created");

                    var url = listurl+"DispForm.aspx?ID=" + id;

                    var liHtml = "<li><a href="+url+" target='_blank'>" + GetChars(title,tlength);                   

                    liHtml +="</a>"                    

                    //判断是否显示新标签

                    if(IsNew(created))

                    {

                       liHtml +="<img src='/_layouts/2052/images/new.gif' />"

                    }

                    liHtml+="</li>"

                    $("#"+ulname).append(liHtml);

                });

            }

        });

   

   }

//获取某个网站某张列表子文件夹下信息

function GetListItemsByFolder(weburl,listname,foldername,listurl,num,tlength,ulname)
{
strQuery = "<Query><Where>" +
"<Contains>" +
"<FieldRef Name= 'FileRef' />" +
"<Value Type='Text'>" + foldername + "</Value>" +
"</Contains>" +
"</Where>"+
"<OrderBy>" +
"<FieldRef Name='Created' Ascending='false'/>" +
"</OrderBy></Query>";
$().SPServices({
operation: "GetListItems",
async: false,
webURL: weburl,
listName: listname,
//CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='Created' /></ViewFields>",
CAMLQuery: strQuery,
CAMLQueryOptions: "<QueryOptions><ViewAttributes Scope='Recursive'/></QueryOptions>",
CAMLRowLimit: num,
completefunc: function(xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
var id = $(this).attr("ows_ID");
var title=$(this).attr("ows_Title");
var created=$(this).attr("ows_Created");
var thisFSObjType = $(this).attr("ows_FSObjType").split(";#")[1];
var thisFileRef = $(this).attr("ows_FileRef").split(";#")[1];
var url;
if(thisFSObjType ==1)
{
url ="/" + thisFileRef;
}else
{
url = listurl+"DispForm.aspx?ID=" + id;
}
var liHtml = "<li>·<a href="+url+" target='_blank'> " + GetChars(title,tlength);
liHtml +="</a>"
//判断是否显示新标签
if(IsNew(created))
{
liHtml +="<img src='/_layouts/2052/images/new.gif' />"
}
liHtml+="</li>"
$("#"+ulname).append(liHtml);
});
}
});
}

 

2、获取某条信息附件信息

function GetItemAttachment(weburl,listname,itemid,ulname)

{

  $().SPServices({

  operation: "GetAttachmentCollection",

  webURL: weburl,

  listName: listname,

  ID: itemid,

  completefunc: function(xData, Status) {

    var output = "";



    $(xData.responseXML).find("Attachments > Attachment").each(function(i, el) {

      var $node = $(this),

        filePath = $node.text(),

        arrString = filePath.split("/"),

        fileName = arrString[arrString.length - 1];



      output += "<li><a href='" + filePath + "' target='_blank'>" + fileName + "</a></li>";

    });



    $("#"+ulname).append(output);

  }

});

}

 

你可能感兴趣的:(SharePoint)