码迷,mamicode.com
首页 > 其他好文 > 详细

利用SPServices制作纯静态sharepoint页面

时间:2014-06-10 20:38:15      阅读:421      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   java   http   

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

以下例子仅供参考:

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

bubuko.com,布布扣
//判断是否是新信息
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);
});
}
});
}

 
bubuko.com,布布扣

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

bubuko.com,布布扣
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);
  }
});
}
bubuko.com,布布扣

 

利用SPServices制作纯静态sharepoint页面,布布扣,bubuko.com

利用SPServices制作纯静态sharepoint页面

标签:style   class   blog   code   java   http   

原文地址:http://www.cnblogs.com/lrforever/p/3779506.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!