如何使用JQuery或JavaScript获取特定列表中View的值?
答案 0 :(得分:0)
function getItemsFromView(listTitle, viewTitle) {
var context = new SP.ClientContext.get_current();
var list = context.get_web().get_lists().getByTitle(listTitle);
context.load(list);
var view = list.get_views().getByTitle(viewTitle);
context.load(view);
context.executeQueryAsync(
function (sender, args) {
var query = new SP.CamlQuery();
query.set_viewXml("<View><Query>" + view.get_viewQuery() + "</Query></View>");
var items = list.getItems(query);
context.load(items);
context.executeQueryAsync(
function () {
var listEnumerator = items.getEnumerator();
return listEnumerator; // Return List Item array
},
function (sender, args) { alert("error in inner request: " + args.get_message()); }
);
},
function (sender, args) { alert("error: " + args.get_message()); }
);
}
//Example of usage
var listItems = getItemsFromView("Tasks", "My Tasks");
var i = 0;
while (listEnumerator.moveNext()) {
i++;
}
alert("items retrieved: " + i);
以下是一个类似的问题供您参考:
JavaScript library to get list items based on a view using CSOM/JSOM