02-12-2020 08:33 AM
Hi,
I want to loop through sub-folders of a certain folder via javascript. My code looks like this:
function processNodes(myNodes) { for (i = 0; i < myNodes.length; i++) { doSomething(myNodes[i]); if (recursive) { childNodes = myNodes[i].childFileFolders(false, true); if (childNodes.length) { processNodes(childNodes); } } } } var referenceType = "node"; var reference = ["workspace", "SpacesStore", "e2686b75-7ebf-45a3-8364-7613001c6e14"]; foundNode = search.findNode(referenceType, reference); nodes = foundNode.childFileFolders(false, true); processNodes(nodes);
The nodes = foundNode.childFileFolders(false, true); returns two folders. But the function processNodes only handles the first one. I would expect that it also handles the second one because recursive = true. But it does not. What am I doding wrong?
Thanks,
Patrick
02-12-2020 09:37 AM
Hi @patrickvanhoof ,
Have you thought of using a query instead => https://hub.alfresco.com/t5/alfresco-content-services-forum/list-all-folder-subfolders-files-via-web...
This might be more efficient than walking a heavily populated tree?
HTH
02-12-2020 09:37 AM
Hi @patrickvanhoof ,
Have you thought of using a query instead => https://hub.alfresco.com/t5/alfresco-content-services-forum/list-all-folder-subfolders-files-via-web...
This might be more efficient than walking a heavily populated tree?
HTH
02-13-2020 02:43 AM
Hi,
nodes = search.query({ language: 'fts-alfresco', query: 'ANCESTOR:"workspace://SpacesStore/e2686b75-7ebf-45a3-8364-7613001c6e14"', maxItems: 2000 });
This indeed works much better/faster.
Thanks.
Patrick
02-13-2020 05:19 AM
Hi @patrickvanhoof,
Thanks for reporting back - and for the code snippet. Will help other people in the same situation.
Are you thinking about attending DevCon 2020? Full session speakers get a free ticket!
Explore our Alfresco products with the links below. Use labels to filter content by product module.