code -
function runCode()
{
var context = new SP.ClientContext.get_current();
var list = context.get_web().get_lists().getByTitle("listName");
var view = list.get_views().getByTitle("All Items");
context.load(view);
context.executeQueryAsync(
function (sender, args) { getItemsFromList("listname", "<View><Query>" + view.get_viewQuery() + "</Query></View>") },
function (sender, args) { alert("error: " + args.get_message()); }
);
}
function getItemsFromList(listTitle, queryText)
{
var context = new SP.ClientContext.get_current();
var list = context.get_web().get_lists().getByTitle(listTitle);
var query = new SP.CamlQuery();
query.set_viewXml(queryText);
var items = list.getItems(query);
context.load(items);
context.executeQueryAsync(
function () {
var text = "";
var itemCount = items.get_count();
for (var i = 0; i < itemCount; i++) {
text += items.get_item(i).get_item("Title") +";";
}
},
function (sender, args) { alert("error in inner request: " + args.get_message()); }
);
}
Ads by Google
No comments:
Post a Comment