You can also check whether item is folder or list item using "FileSystemObjectType"
var context = SP.ClientContext.get_current();
var web = context.get_web();
//doc is a document library server relative url
var folder = web.getFolderByServerRelativeUrl("Documents/Wildlife");
//var parentFolder = folder.get_parentFolder();
//context.load(parentFolder);
context.load(folder);
context. executeQueryAsync(function(){
var query = new SP.CamlQuery();
query.set_folderServerRelativeUrl(folder.get_serverRelativeUrl());
var allItems = list.getItems(query);
context.load(allItems, "Include(Title, FileSystemObjectType, File)");
context.executeQueryAsync(function(){
debugger;
var itemsEnumerator = allItems.getEnumerator();
while(itemsEnumerator.moveNext()){
var item = itemsEnumerator.get_current();
var fileType = item.get_fileSystemObjectType();
//get the detailed information
var title = item.get_item("Title")
}
}, function(sender, args){debugger;});
}, function(sender, args){debugger;});
var context = SP.ClientContext.get_current();
var web = context.get_web();
//doc is a document library server relative url
var folder = web.getFolderByServerRelativeUrl("Documents/Wildlife");
//var parentFolder = folder.get_parentFolder();
//context.load(parentFolder);
context.load(folder);
context. executeQueryAsync(function(){
var query = new SP.CamlQuery();
query.set_folderServerRelativeUrl(folder.get_serverRelativeUrl());
var allItems = list.getItems(query);
context.load(allItems, "Include(Title, FileSystemObjectType, File)");
context.executeQueryAsync(function(){
debugger;
var itemsEnumerator = allItems.getEnumerator();
while(itemsEnumerator.moveNext()){
var item = itemsEnumerator.get_current();
var fileType = item.get_fileSystemObjectType();
//get the detailed information
var title = item.get_item("Title")
}
}, function(sender, args){debugger;});
}, function(sender, args){debugger;});
No comments:
Post a Comment