Quantcast
Channel: SharePoint 2010 - Development and Programming forum
Viewing all articles
Browse latest Browse all 11508

JavaScript Client Object Model - How to batch up multiple queries in one round trip?

$
0
0

Hi,

I've tried to do something like get 3 list items from 3 lists. I can see that the items do get retrieved in the callback but when I try to access them, it complains saying the item is not loaded yet or needs to be explicitly retrieved and then the item suddenly becomes unloaded (ie all the properties I saw are now suddenly gone). Am I missing something? My sample code is below:-

var ctx = new SP.ClientContext(siteUrl);
var lists = ctx.get_web().get_lists();
this.ListItem1 = lists.getByTitle("List1").getItemById(1);
this.ListItem2 = lists.getByTitle("List2").getItemById(2);
this.ListItem3 = lists.getByTitle("List3").getItemById(3);
ctx.load(this.ListItem1);
ctx.load(this.ListItem2);
ctx.load(this.ListItem3);
ctx.executeQueryAsync(onItemRetrievalSucceeded, onItemRetrievalFailed);

function onItemRetrievalSucceeded(sender,args) {
/* alert(this.ListItem1.get_item("Title")) */ // this fails saying the item is not ready??
}

function onItemRetrievalFailed(sender,args) {
 /* handle error */
}

Any help would be much appreciated.

Kind Regards

Chris


Viewing all articles
Browse latest Browse all 11508

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>