sharepoint - Get all lists root folder with SP.js -
I need to get all root folders of lists on the current web, along with the shrepoint client object model.
I try to use this code, but I have an error
var context = SP.ClientContext.get_current (); Var lists = context.get_web () Get_lists (); Context.load (listings); Context.executeQueryAynync (function (sender, args) {var enumerator = lists.gateAnimator (); while (enumerator.movext ()) {var list = enumerator.get_current (); var rootFolder = list.get_rootFolder (); context.load (Rootfolder, 'server rtUurl'); references.exeaccacaccc (function (sender, args) {// error var url = rootFolder.get_serverRelativeUrl (); console.log (url);}, function (sender, args) {console.log ('Error');});}}, function (sender, args) {console.log ('error');}); thanks
This error occurs because this request is not requested it was done.
Change the List.RootFolder line to load: context.load (listings); with this one:
context.load (lists, 'include (rootfolder)'); But there are other drawbacks in the specified example:
- Because async is used in a loop, This <
ServerRelativeUrl property P> A fixed version is displayed below which prints the root folder for all the lists: var context = SP.ClientContext.get_current (); Var lists = context.get_web () Get_lists (); context.load (include lists, '(RootFolder)'); Context.executeQueryAsync (function () {var enumerator = lists.getEnumerator (); while (enumerator.moveNext ()) {var list = enumerator.get_current (); var rootFolder = list.get_rootFolder (); var url = rootFolder.get_serverRelativeUrl (); Console.log (url);}}, function (sender, args) {console.log ('error');});
Comments
Post a Comment