所以我试图在我之前的问题(SharePoint SOAP GetListItems VS jQuery - Need some advice on how to use Ajax to cycle through Custom List items as well as Ajax refresh the list contents)中实现向我建议的解决方案。我想使用此处找到的循环库:http://malsup.com/jquery/cycle2/循环遍历我使用自定义SharePoint列表中的行填充的DIV的内容。我正在创建的html似乎是有效的,但是当我尝试运行下面的循环代码时,我得到:
Error: $("#tasksUL").cycle is not a function
Source File: http://ourdomain.net/Pages/Default.aspx
Line: 426
以下是我在内容编辑器Web部件中阻止的代码:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="/SiteCollectionDocuments/jquery.timers-1.0.0.js"></script>
<script type="text/javascript" src="/SiteCollectionDocuments/jquery.cycle.all.2.72.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)
{
var liHtml = "";
$(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
liHtml = liHtml + "<div><h3>" + $(this).attr("ows_Title") + "</h3><p>" + notice_images + $(this).attr("ows_Body") + "</p></div>";
});
// assign output to DIV tags
$("#tasksUL").html(liHtml);
}
</script>
<script type="text/javascript">
$(document).ready(function() {
$('#tasksUL').cycle({
fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
});
});
</script>
<div id="tasksUL"> </div>
代码按预期启动,但我想知道我在循环功能方面做错了什么...我已经尝试显式链接到上面包含的所有JavaScript文件,我可以在浏览器中访问它们没有问题。为了正确使用这个库,我是否需要为#tasksUL实际定义CSS?在代码中有什么明显的东西我需要冲在脸上吗?谢谢!
答案 0 :(得分:1)
你从哪里得到jquery.cycle ... js?
至少jQuery Cycle Plugin homepage的zip文件似乎在文件名的末尾有一些奇怪的附加字符。当我解压缩它时,我的文件被称为jquery.cycle.all.min.js_
而不是jquery.cycle.all.min.js
答案 1 :(得分:1)
实际上,任何人都无法知道这一点,之所以失败是因为有人安装了一个旧的网站集jQuery包,并且与jCycle的效果不佳。一旦我在集合上停用了该功能,重新启动了IIS并刷新了页面,一切正常。作为额外的步骤,我将最新的完整版jQuery下载到文档库中并链接到它而不是Google托管的脚本版本。所以我现在使用的所有j都存在于网站集中。
我能够弄清楚jQuery的冲突版本,但使用Firebug的控制台和脚本调试器。我不得不将调试器设置为停止所有错误,但是出现的第一个错误是引用网站集jQuery包而不是我包含的Google代码。这就是我回答自己问题的原因。还有其他可怜的混蛋正在进行SharePoint开发,他们可能不会使用FireFox测试他们的SP安装,因为它有利于IE和所有它。
感谢所有阅读和回答/评论过的人!