本文介绍了的SharePoint SOAP GetListItems VS jQuery的 - 需要关于如何使用Ajax循环自定义列表项目,以及一些建议作为阿贾克斯刷新列表内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jQuery经由GetListItems方法来访问共享点2007的SOAP接口读取anouncements的自定义列表以这样的方式,以具有该列表刷新每分钟一次的情况下(列表的拥有者添加新的内容,使新的内容变得可见,而无需对最终用户刷新其SharePoint屏幕)。我想这样做,不仅刷新列表,我想通过一个有一次在列表中周期的每个项目(也许有每个项目保持可见10秒钟,那么下一个项目将加载到该空间。

I am using jQuery to access Sharepoint 2007's SOAP interface via the GetListItems method to read in a custom list of anouncements in such a way as to have that list refresh once a minute (in case the owners of the list add new content, so that the new content becomes visible without having the end user refresh their sharepoint screen). WHat I would like to do is not only refresh that list, I would like to have each item in the list cycle through one at a time (maybe have each item stay visible for 10 seconds, then the next item would load into that space.

下面是code我到目前为止有:

Here is the code I have so far:

<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="/SiteCollectionDocuments/jquery.timers-1.0.0.js" ></script>  
<script type="text/javascript">

$(document).ready(function() {

// Create the SOAP request        
// NOTE: we need to be able to display list attachments to users, hence the addition of the
// <queryOptions> element, which necessitated the addition of the <query> element

var soapEnv =
"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>
<soapenv:Body> \
   <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
     <listName>testlist</listName> \
     <viewFields> \
       <ViewFields> \
         <FieldRef Name='Title' /> \
         <FieldRef Name='Body' /> \
         <FieldRef Name='ID' /> \
         <FieldRef Name='Attachments' /> \
       </ViewFields> \
     </viewFields> \
     <query> \
       <Query /> \
     </query> \
     <queryOptions> \
       <QueryOptions> \
         <IncludeAttachmentUrls>TRUE</IncludeAttachmentUrls> \
       </QueryOptions> \
     </queryOptions> \
    </GetListItems> \
  </soapenv:Body> \
  </soapenv:Envelope>";

// call this SOAP request every 20 seconds
$("#tasksUL").everyTime(20000,function(i){
    // our basic SOAP code to hammer the Lists web service
    $.ajax({
    url: "http://ourdomain.net/_vti_bin/lists.asmx",
    type: "POST",
    dataType: "xml",
    data: soapEnv,
    error: printError,
    complete: processResult,
    contentType: "text/xml; charset=\"utf-8\""
    });
  });
});

// basic error display that will pop out SOAP errors, very useful!
function printError(XMLHttpRequest, textStatus, errorThrown)
{
 alert("There was an error: " + errorThrown + " " + textStatus);
  alert(XMLHttpRequest.responseText);
}


// main method that will cycle through the SoAP response nodes
function processResult(xData, status) 
{

  $(xData.responseXML).find("z\\:row").each(function() 
  {
    // resets display element
   $("#tasksUL").empty();

   // gets attachments array - if there is more than one attachment,
   // they get seperated by semi-colons in the response
   // they look like this natively (just an example):
   // ows_Attachments = ";#http://server/Lists/Announcements/Attachments/2/test.txt;
   // #http://server/Lists/Announcements/Attachments/2/UIP_Setup.log;#"

       var mySplitResult = $(this).attr("ows_Attachments").split(";");
  // set up storage for later display of images
  var notice_images = "";

  // processes attachments - please forgive the kludge!  
  for(i = 0; i < mySplitResult.length; i++)
  {
   // check to see the proper link URL gets chosen
   if (i % 2 != 0 && i != 0)
   {
    // strips out pound sign
    mySplitResult[i] = mySplitResult[i].replace("#", "");

    // (possibly redundant) check to make sure element isn't simply a pound sign  
    if (mySplitResult[i] != "#")
    {
     // adds an img tag to an output container
     notice_images = notice_images + "<img src='" + mySplitResult[i] + "' border='0' align='right' style='float:right;' /><br />"; 
    }
   }
  }

  // create final output for printing
  var liHtml = "<h3>" + $(this).attr("ows_Title") + "</h3><p>" + notice_images + $(this).attr("ows_Body") + "</p>";

  // assign output to DIV tags
    $("#tasksUL").html(liHtml);

   });

}
</script>

<div id="tasksUL"/>&nbsp;</div>

这是pretty的简单的东西为止(虽然寻找体面的文件,以你能够做的GetListItem SOAP请求是令人生畏)。里面,我通过返回的行迭代(该PprocessResult功能)块,我重置HTML被分配到DIV块,以便只有一个行显示为输出。在code设置的方式,这意味着只有在我的自定义列表的最后一行是可见的,因为我没有code暂停迭代。

It's pretty simple stuff so far (although finding decent documentation as to what you are able to do with the GetListItem SOAP request was daunting). Inside of the block where I iterate through the returned rows (the PprocessResult function), I am resetting the HTML being assigned to the DIV block so that only one row is showing as output. The way the code is set up, this means only the very last row in my custom list will be visible, as I have no code pausing the iterations.

我的想法一直包裹的code这个街区的定时器:

My thought had been to wrap a timer around this block of code:

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

不过,我会见了零或混合的结果。

But I met with zero or mixed results.

我的问题给大家的是:什么是建立我目前的code既刷新源列表数据的最佳方式就像现在循环就是通过从列表中选择一个查询结果的时间(preferably有一个小小的停顿在每个项目上,让人们可以阅读它)?

My question to you all is: What would be the best way to set up my current code to both refresh the source list data like it is now AND cycle through query results from that list one at a time (preferably with a small pause on each item so that people can read it)?

感谢你了!

迈克

推荐答案

我会保持你的视觉周期和数据更新周期作为独立的实体。

I would keep your visual cycle and your data update cycle as separate entities.

设置您的超时功能,更新的div内显示的数据的容器。您可以添加,并从该列表中你的愿望删除。

Set up your timeout function to update a container of divs with your data displayed inside. You can add and remove from this list to your desire.

您可能开始是这样的:

<div id="container">
  <div id="1" class="task">task foo</div>
  <div id="2" class="task">task bar</div>
  <div id="3" class="task">task baz</div>
</div>

然后一个数据更新后,它可以添加其他元素:

And then after a data update it could add another element:

<div id="container">
  <div id="1" class="task">task foo</div>
  <div id="2" class="task">task bar</div>
  <div id="3" class="task">task baz</div>
  <div id="4" class="task">task lol</div>
</div>

然后用周期插件简单循环的div的有序集合给定容器元素中。这将永远只是显示下一个分区的集合,而不是依赖于您的更新插件重新启动循环。

Then use a cycle plugin to simply cycle through the ordered collection of divs inside of a given container element. It will always just show the next div in the collection, rather than rely on your update plugin to restart the cycle.

通过jQuery的元素最流行的插件周期jquery.cycle.js在的http:// malsup。 COM / jQuery的/循环2 / 。您还可能有兴趣在精简版的版本,可在网上。

The most popular plugin to cycle through elements in jQuery is jquery.cycle.js at http://malsup.com/jquery/cycle2/ . You may also be interested in the 'lite' version that is available online.

这篇关于的SharePoint SOAP GetListItems VS jQuery的 - 需要关于如何使用Ajax循环自定义列表项目,以及一些建议作为阿贾克斯刷新列表内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 02:53