我在下面的代碼中使用Sharepoint設計插入內容webpart。帶Sharepoint和Divs的SPServices
該代碼列出了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>