javascript API i Sharepoint
By Anatoly Mironov
Det är supersmidigt. Här är ett exempel:
function createAnnouncement(title, body) {
var ctx = new SP.ClientContext.get\_current();
var list = ctx.get\_web().get\_lists().getByTitle('Meddelanden');
var itemCreationInfo = new SP.ListItemCreationInformation();
this.newListItem = list.addItem(itemCreationInfo);
this.newListItem.set\_item("Title", title);
this.newListItem.set\_item("Body", body);
this.newListItem.update();
ctx.executeQueryAsync(
Function.createDelegate(this, this.onSucceededCallback), Function.createDelegate(this, this.onFailedCallback));
}
function onSucceededCallback(sender, args) {
SP.UI.Status.addStatus("Info", "It worked!",true);
}
function onFailedCallback(sender, args) {
SP.UI.Status.addStatus("Info", "It didn't work!",true);
}
Comments from Wordpress.com
westerdaled - Feb 0, 2013
Thanks, I gather I can pass OnSucceedCallback as a delegate. As you say I can also pass anything that will influence the CAML query as parameter to the delegate method. Thanks again for your advice.
Anatoly Good post. I have a related question. If you wanted a number of pages to all reuse a csom js function that populates a list object based on unique CAML query set on the page via the method shown below. The only thing is that there seems no way for onSucceededCallback to pass back the list or array or json array or whatever to the page that requested it. So am I cursed with the burden of having an individual OnSucceededCallback per each page. function getListItemsForCategory(subMenuCat) { // context.executeQueryAsync(onSucceededCallback, onFailedCallback); return mypopulatearrayorwhatever }
Hi. If there are some variables in OnSucceededCallback, just make them to parameters. Post some more code if you want a more detailed answer :)