我正在使用 SPServices 获取 SharePoint (2010) 列表项
function GetListItemData() {
var container = $("#container");
$(container).html("");
var datarows = [];
// get list data
$().SPServices({
webUrl: "https://",
operation: "GetListItems",
async: false,
listName: myList, // Using GUID should work across multisite apps
CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='Body' /><FieldRef Name='PublishingPageImage' /><FieldRef Name='PublishingImageCaption' /></ViewFields>",
completefunc: function(xData, Status){
$(xData.responseXML).SPFilterNode("z:row").each(function(){
var x={
name: myList,
title: $(this).attr("ows_Title"),
image: $(this).attr("ows_PublishingPageImage"),
caption: $(this).attr("ows_PublishingImageCaption"),
body: $(this).attr("ows_Body")
};
datarows.push(x);
});
}
});
我现在正在通过各种列表链接上的 data- attr 更新内容并再次运行该功能。
循环浏览所有列表以创建所有列表的仪表板的适当/最佳方法的任何线索?
任何方向都非常感谢。
Lists.GetListCollection Method 返回网站中所有列表的列表信息。
SPS服务示例
function getListCollection(completeFn)
{
$().SPServices({
operation: "GetListCollection",
completefunc: function( xData, Status ) {
var lists = [];
$( xData.responseXML ).find("Lists > List").each(function(i,el) {
var listJson = listXml2Json(el.outerHTML);
lists.push(listJson);
});
completeFn(lists);
}
});
}
function listXml2Json(value)
{
var jsonObject = {};
var schemaXml = $.parseXML(value);
$(schemaXml).find('List').each(function() {
$.each(this.attributes, function(i, attr){
jsonObject[attr.name] = attr.value;
});
});
return jsonObject;
}
//print lists title
getListCollection(
function(lists){
lists.forEach(function(list){
console.log(list.Title);
});
});