mardi 23 décembre 2014

fetch of all items from a list



I have an Announcement list in SharePoint site,I need to show all announcement in homepage,I am following msdn code sample to retrieve items from the list,But only last item will be display.



function Fetchdata() {
var ctx = new SP.ClientContext(appWebUrl);//Get the SharePoint Context object based upon the URL
var appCtxSite = new SP.AppContextSite(ctx, hostWebUrl);
var web = appCtxSite.get_web();
var list = web.get_lists().getByTitle("Announcement");

var camlQuery = new SP.CamlQuery();
//camlQuery.set_viewXml('<View><Query><Where><Geq><FieldRef Name=\'Title\'/>' +
// '<Value Type=\'Text\'>Annoucement1</Value></Geq></Where></Query><RowLimit>10</RowLimit></View>');
this.collListItem = list.getItems(camlQuery);

ctx.load(collListItem);


ctx.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

}

function onQuerySucceeded(sender, args) {

var listItemInfo = '';



var listItemEnumerator = collListItem.getEnumerator();
while (listItemEnumerator.moveNext()) {

var oListItem = listItemEnumerator.get_current();

listItemInfo = oListItem.get_item('Title');
listItemInfo = oListItem.get_item('Body');
}
}

document.getElementById('title1').innerHTML = listItemInfo.toString();
document.getElementById('body1').innerHTML = listItemInfo.toString();







function onQueryFailed(sender, args) {

alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}







0 commentaires:

Enregistrer un commentaire