Here are the other function 'browse' and Server_browse.
The function 'Server_browse' consigns an Folder or Variable to the function 'browse'. In 'browse' i will added the Variable in an array or call 'Server_browse' again, if the Item a folder. Current I get all Folders and Variables seperate on 'console.log(result.elements)'. But i willl write all folders and variables in an Array.
var browse = function(item,indx,array,callback){
// 'item' is a Folder or Variable which i get from the server
//item = {"MyVariable1":{"referenceTypeId":"ns=0;i=46","isForward":true,"nodeId":"ns=1;i=1005","browseName":{"namespaceIndex":0,"name":"MyVariable1"},"displayName":{"text":"MyVariable1"},"nodeClass":"Variable","typeDefinition":"ns=0;i=63"}};
var child = ns='+item.browseName.namespaceIndex+';i='+item.nodeId.value;
if (item.$nodeClass.key == 'Variable') {
callback(item);
}else{
Server_browse(child,function(result){
callback(result);
});
}
}
var Server_browse = function(item,callback){
node_browse.session.browse( item,function (err, itemResults,diagnostics) {
if (err) {
console.log(err);
console.log(itemResults);
console.log(diagnostics);
}else{
for(var i=0; i<itemResults.length; i++){
itemResults[i].references.forEach(function(element,index,arr){
browse(element, index, arr, function(item){
callback(item);
});
});
}
}
});
}