我正在使用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在各种列表的链接上更新内容并再次运行该功能。
是否有正确/最好的方式循环遍历所有列表以创建所有列表的仪表板?
非常感谢任何方向。
答案 0 :(得分:1)
Lists.GetListCollection Method返回网站中所有列表的列表信息。
SPServices示例
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);
});
});