代码如下:
var curContext = null;
var curWeb = null;
var picListTitle = "PictureLib";
var folderName = "PictureSlide";
var liTemp = "<li style='background-image: url({0});'></li>"; $(document).ready(function () {
curContext = SP.ClientContext.get_current();
curWeb = curContext.get_web(); ShowSlidePics(); }); function ShowSlidePics()
{
var camlQuery = SP.CamlQuery.createAllFoldersQuery();
//var folderUrl = "/teams/ap1/gctech/DEV/PictureLib/" + folderName+"/"; ///teams/ap1/gctech/DEV
//camlQuery.set_folderServerRelativeUrl(folderUrl);
camlQuery.set_viewXml("<View Scope='RecursiveAll'><Query><Where><Contains><FieldRef Name='FileDirRef'/><Value Type='Text'>/PictureSlide</Value></Contains></Where></Query></View>"); var picList = curWeb.get_lists().getByTitle(picListTitle);
var fileItems = picList.getItems(camlQuery);
curContext.load(fileItems, 'Include(ID, Title, FileRef)');//, FileLeafRef, FileDirRef
curContext.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded), Function.createDelegate(this, onQueryFailed)); function onQuerySucceeded(sender, args) {
var itemInfo = '';
var itemEnumerator = fileItems.getEnumerator(); while (itemEnumerator.moveNext()) {
var item = itemEnumerator.get_current();
itemInfo += liTemp.replace("{0}", item.get_item('FileRef'));
} $("#divBanner ul").html(itemInfo); StartBindSlide();
}
function onQueryFailed(sender, args) {
console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
} function StartBindSlide()
{
$('#divBanner').unslider({
speed: 500, // speed
delay: 3000, // delay
keys: true, // enable Key
dots: true // dots
}); var unslider = $('#divBanner').unslider();
$('.unslider-arrow').click(function () {
var fn = this.className.split(' ')[1];
// Either do unslider.data('unslider').next() or .prev() depending on the className
unslider.data('unslider')[fn]();
});
}
}