javascript iterate trough object to get dirnames and get files from them
with phonegap (solved)
_verhalen = JSON.parse(verhalen);
for(key in _verhalen){
console.log(_verhalen[key]);
requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(filesys) {
filesys.root.getDirectory("story/save/"+_verhalen[key], {create:
false }, function(dirName) {
console.log(_verhalen[key]);
var directoryReader = dirName.createReader();
directoryReader.readEntries(function(entries){
$("#swipe").append('<div class="img_wrapper"><img
height="205" width="300"
src="file://'+entries[0].fullPath+'?'+Math.random()+'"
onclick="loadproject(''+_verhalen[key]+'')"/></div>');
},function (error) {
alert("couldn't load image");
});
},function (error) {
alert("couldn't load directory");
});
},function (error) {
alert("couldn't load filesystem");
});
}
well to start of i need to do some explanation, i get directoryname from
variable _verhalen[key] it sits in a loop while i iterate over it. on
first console output i get value1 and value2, but from the second output
which sits in requestFileSystem i get value2 and value2
i think this bug comes because requestFileSystem runs asynchronous so the
iteration finishes before filesystem could finish first operation and
that's why second output has same values.
any ideas on how to fix such issue ?
found soulution moved requestFileSystem to a function so now my code looks
like : iteration { call_to_function(_verhalen[key]); } and function has
requestFileSystem loop
No comments:
Post a Comment