我正在使用 Sharepoint Design,并在内容 webpart 中插入以下代码。
该代码列出了带有库的 SPServices 的文件和文件夹,并在单击链接时显示 PDF。在我的库PDFLibrary
中,我有一些文件夹,每个文件夹里面都有一些文件。代码运行良好,但我现在的问题是如何以手风琴效果显示这些菜单?
我特意在 h3 标签之间生成了文件夹名称,但我需要在每个链接组上使用分隔符:
h3 PDF Folder1 /h3
div
link file1
link file2
link file3
/div
这样,在我的代码中,当我尝试在链接前插入一个 div 时,浏览器会立即将其关闭:
h3 PDF Folder1 /h3
div /div (<= HERE IS WRONG!)
link file1
link file2
link file3
我找到的解决方案是在页面完全加载后插入另一个带有手风琴代码的 webpart,但这并不理想。
动态插入的 div 是不可能的吗?
这是我的代码:
<script type="text/javascript" src="/Scripts/pdfobject.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function () {
// var to generate ids for each element of list
var _id = 1;
$().SPServices({
operation: "GetListItems",
listName: "PDFLibrary",
completefunc: function (xData, Status) {
$(xData.responseXML).find("z\\:row, row").each(function() {
//take the type of object. 1 = folder / 0 = file
var thisFSObjType = $(this).attr("ows_FSObjType").split(";#")[1];
if(thisFSObjType == 1) {
//mount the string to get the current folder
var _initialString = "<QueryOptions><Folder>PDFLibrary/";
var _folderName = $(this).attr("ows_LinkFilename");
var _finalString = "</Folder></QueryOptions>"
var _CAMLQueryString = _initialString + _folderName + _finalString;
//print the current folder on div
$("#pdflist").append(_folderName).append("<br/>");
//this function lists the files inside the current folder
$().SPServices({
operation: "GetListItems",
async: false,
listName: "PDFLibrary",
CAMLQueryOptions: _CAMLQueryString,
completefunc: function (xData, Status) {
$(xData.responseXML).find("z\\:row, row").each(function () {
var _url = 'http://mysite.org/' + $(this).attr("ows_FileRef").split(";#")[1];
var _title = $(this).attr("ows_LinkFilename");
var _link = $("<a href='" + _url + "'" + "id='" +_id + "'" + "/>");
$(_link).append(_title);
$("#pdflist").append(_link).append("<br/>");
// set id to current file
var idpdf = "#" + _id;
// load file into pdfview div
$(idpdf).click(function(event){
event.preventDefault();
var myPDF = new PDFObject({
url: $(this).attr('href'),
pdfOpenParams: {
navpanes: 1,
view: "FitV",
pagemode: "thumbs"
}
}).embed("pdfview");
});
_id = _id + 1;
});
$("#pdflist").append("<br/>");
}
});
}
});
}
});
});
</script>