Problem is below I have a arr_x array, and I call "call_when_drop" function like below:
<body ondrop="call_when_drop(event,this);" ></body>
Then it begin to create array elements.when I console log array length I see only 1, but when I console log a few seconds later I see all number of members of array.But interesting thing is that when I console.log array it self I am able to see all elements.
below function is belong to here Does HTML5 allow drag-drop upload of folders or a folder tree?
var arr_x=[];
function traverseFileTree(item, path,connection_time) {
if(arr_x.length>25){
return arr_x;
}
arr_x[arr_x.length]=arr_x.length;
path = path || "";
if (item.isFile) {
} else if (item.isDirectory) {
var dirReader = item.createReader();
//console.log(dirReader);
dirReader.readEntries(function(entries) {
var dir=[];
for (var i=0; i<entries.length; i++) {
traverseFileTree(entries[i], path + item.name + "/",connection_time);
}
});
}
return arr_x;
}
This function called when user drop folder to browser
function call_when_drop(e,element){
var items = e.dataTransfer.items;
for (var i = 0, item; item = items[i]; ++i) {
if (item.kind == 'file') {
var a = traverseFileTree(item.webkitGetAsEntry(),"");
console.log(arr_x);
console.log('with_setTimeout');
console.log(arr_x.length);
console.log('---------------------------------------');
setTimeout(function(){
console.log('with_setTimeout');
console.log(arr_x.length);
},300);
}
}
}
Note: I notice that if I change traverseFileTree
function like below it works but I need before function's working version
function traverseFileTree(item, path,connection_time) {
if(arr_x.length>25){
return arr_x;
}
arr_x[arr_x.length]=arr_x.length;
traverseFileTree();
return arr_x;
}