10-11-2019 04:18 AM
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
10-11-2019 05:26 AM
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.
10-11-2019 06:11 AM
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.
Explore our Alfresco products with the links below. Use labels to filter content by product module.