I would like to know how to get subweb lists using CSOM. I actually know how to get lists on a web and how to get a sub web collection but I can't figure out how to get lists on sub web collection.
Let's say we have the following web hierarchy.
http://www.web/web1
http://www.web/web2
http://www.web/...
How to iterate on web1, web2, etc and getting for example the list http://www.web/web42/Lists/myPrecious/. ?
I have been that far:
function displayLists() {
var context = new SP.ClientContext.get_current();
var web = context.get_web();
webCollection = web.getSubwebsForCurrentUser(null);
context.load(webCollection);
context.executeQueryAsync(Function.createDelegate(this, success), Function.createDelegate(this, error));
}
function success() {
var webEnumerator = webCollection.getEnumerator();
while (webEnumerator.moveNext())
{
var web = webEnumerator.get_current();
var list = web.get_lists().getByTitle("myPrecious");
var title = list != null ? list.get_title() : "nothing";
console.log(title);
}
}
function error(sender, args) {
alert('Request failed. ' + args.get_message() +
'\n' + args.get_stackTrace());
}
I'm getting the error
"The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested."