在SharePoint和使用SPServices时,我试图查看文档库中特定子文件夹的文件夹内容(而不是库中的每个文件和文件夹)。图书馆结构如下所示:
列表名称:共享文档
- Subfolder #5
- File #8
- File #9
用GetListItems列出顶级文件夹是很容易的,但是我想让用户点击其中一个文件夹和列表,只列出子文件夹的直接子文件夹。
因此,如果有人单击“文件夹#1”,那么我只想向他们展示以下内容:
我完全不知道如何列出特定子文件夹的直接子文件夹。
有人能帮忙吗?
发布于 2014-06-21 09:49:29
为了限制对特定文件夹的查询,可以指定具有Folder值的Folder参数:
<QueryOptions>
<Folder>/SiteName/Lists/Links/folder/subFolder</Folder>
</QueryOptions>示例
var listName = "Shared Documents";
var folderName = "/Shared Documents/Folder #1";
$().SPServices({
operation: "GetListItems",
async: false,
listName: listName,
CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
CAMLQueryOptions: "<QueryOptions><Folder>" + folderName + "</Folder></QueryOptions>",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
var title = $(this).attr("ows_Title");
console.log(title);
});
}
});请跟随这条线了解更多细节。
发布于 2014-06-20 18:21:42
您可以使用名为SPServices的JavaScript API,而不是SharepointPlus (如果希望保留SPServices,请参见末尾)。做你想做的事有两种方法:
使用第一个选项,您只能调用以下代码一次,然后您必须将结构存储在某个地方:
$SP().list("Shared Documents Library").get({
fields:"BaseName,FileRef,FSObjType", // "BaseName" is the name of the file/folder; "FileRef" is the full path of the file/folder; "FSObjType" is 0 for a file and 1 for a folder (you need to apply $SP().cleanResult())
folderOptions:{
show:"FilesAndFolders_Recursive"
}
}, function(files) {
// in "files" you have ALL the files and folders in your library
for (var i=0; i<files.length; i++) {
console.log(files[i].getAttribute("FileRef"))
}
});对于第二个选项,每次用户单击文件夹时都必须调用下面的代码。例如,如果他单击“文件夹#1":
$SP().list("Shared Documents Library").get({
fields:"BaseName,FileRef,FSObjType", // "BaseName" is the name of the file/folder; "FileRef" is the full path of the file/folder; "FSObjType" is 0 for a file and 1 for a folder (you need to apply $SP().cleanResult())
folderOptions:{
show:"FilesAndFolders_InFolder", /* this option changed from 1) */
path:"Folder #1" /* here is the name of the folder */
}
}, function(files) {
// it will get the files and folders into the "Folder #3"
for (var i=0; i<files.length; i++) {
console.log(files[i].getAttribute("FileRef"))
}
});如果不想在SharepointPlus中使用SPServices,则必须为查询定义queryOptions。如果您使用选项1(上面),那么您的queryOptions将如下所示:
<QueryOptions>
<ViewAttributes Scope="RecursiveAll"></ViewAttributes>
<Folder>http://your.siteweb.com/path/to/site/collection/path/to/Folder #1</Folder>
</QueryOptions>要知道要使用哪个ViewAttributes范围使用你可以检查我的代码,请执行以下操作。
发布于 2014-09-05 19:38:50
若要排列所有文件夹、子文件夹和文件的顺序,请尝试使用以下函数:
<script>
$(document).ready(function(){
var list = "Shared Documents";
var url = "Shared Documents";
createTree(url, 0, list);
});
function createTree(url, ID, list){
//get the url to define the level of tree,
$().SPServices({
operation: "GetListItems",
async: false,
listName: list,
CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='ID' /></ViewFields>",
CAMLQueryOptions: "<QueryOptions><Folder>" + url + "</Folder></QueryOptions>",
completefunc: function (xData, Status) {
$("#"+ID+"").append("<ul id='prime"+ID+"'>");
$(xData.responseXML).SPFilterNode("z:row").each(function() {
var id = $(this).attr("ows_ID");
var title = $(this).attr("ows_Title");
var folder = $(this).attr("ows_FileLeafRef").split(";#")[1];
//var ref = $(this).attr("ows_FileRef").split(";#")[1]; //this field gets the folder or file url
$("#prime"+ID+"").append("<li id='"+id+"'>" +
folder +
//', Link: '+ ref +
" [" +
$(this).attr("ows_FileLeafRef") +
" :: " +
$(this).attr("ows_FSObjType") +
"]" +
"</li>");
var thisFSObjType = $(this).attr("ows_FSObjType").split(";#")[1];
if(thisFSObjType == 1) {
//auto call the function createTree again, to get subfolders and files, assigning a new url/subfolder and id
createTree(url+'/'+folder, id, list);
}
});
$("#"+ID+"").append("</ul>");
}
});
}
</script>
<body>
<div><h1>My Tree</h1></div>
<div id="0">
</div>
</body>如果您想要手风琴功能,请尝试向代码中添加这种引导行为。
诚挚的问候。
https://stackoverflow.com/questions/24328532
复制相似问题