If we take this code example, we can see we need to call a lot of methods to get to our results (.getEnumerator()
, .get_current()
, .get_title()
, .get_title()
)
var siteUrl = '/sites/MySiteCollection';
function retrieveAllListProperties() {
var clientContext = new SP.ClientContext(siteUrl);
var oWebsite = clientContext.get_web();
this.collList = oWebsite.get_lists();
clientContext.load(collList);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}
function onQuerySucceeded() {
var listInfo = '';
var listEnumerator = collList.getEnumerator();
while (listEnumerator.moveNext()) {
var oList = listEnumerator.get_current();
listInfo += 'Title: ' + oList.get_title() + ' Created: ' + oList.get_created().toString() + '\n';
}
alert(listInfo);
}
function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
Is there any built in method will will return the results in the form of a simple data structure, e.g. an array of objects, each object representing a list item, e.g:
[
{ID:1, Title:"value", Author:"value" ...},
{ID:2, Title:"value", Author:"value" ...},
{ID:3, Title:"value", Author:"value" ...}
...
]
Or if I could access the original JSON returned from _vti_bin/client.svc/ProcessQuery
as that has a clean enough structure.
My goal is to pass on a clean data structure to a templating engine like doT.js or Handlebars.js, without the need to loop through and manually build a new data structure using the methods outlined above. Seems like an unnecessary step when a decent structure is right there in the JSON response.