Hello,
I try to do a recursive function to get all files in a node (even if the files are in different subfolders) and to stock them into an array. But the array I return is unexploitable..
The code I use :
function fillArray(alfrescoJsApi: AlfrescoJSApi, node:any, array: Array<any>) { alfrescoJsApi.nodes.getNodeChildren(node).then( function (data) { for(var entry of data.list.entries) { if(entry.entry.isFolder == true) { let id = entry.entry.id; let newAlfrescoApi = <AlfrescoJSApi> new AlfrescoJSApi({ provider: 'ECM' }); fillArray(newAlfrescoApi, id, array); } else if(entry.entry.isFile == true) { array.push( {[entry.entry.id]: entry.entry.name}); } }; }, function (error) { console.log('This node does not exist'); }); return array; }
Any ideas ?
Thanks
First of all, I would recommend moving the JS-API outside the foreach, as you create a lot of client objects and that can hurt performance.
Second, you are using async method call, and then apply for loop where you fire more async things. I think the entire function is not waiting for results correctly.
Thanks for the answer.
I move the JS-API as you suggested.
I have an "array" in return, with Objects in it. I can see it in console.log
But I can't use it. For example, array[0] returns undefined.
Discussions, help and advice about the Alfresco Development Framework.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.