This has been solved with a hack (setting a timeout that waits for the callbacks to finish in the chrome). I didn't know this about JavaScript, that it will jump over code before it finishes other code when dealing with callbacks.. I only knew this to occur with threads in other languages. Maybe a thread is created in the Chrome? Please help me with a better answer if you know.
I'm writing a bookmark manager extension. I've found a way to see the id, title and urls of bookmarks through console, but i need the info saved for further processing in a global array. I placed the global in the loop, but the call back function seems not ignore the global, erase it, or something. The data is not being stored in it. Is there a workaround for this? New to JavaScript.
If you'd like to take a peek at it I have the JavaScript running on a server now. http://75.72.25.11Code:function printBookmarks(bookmarks) { bookmarks.forEach(function(bookmark) { console.debug(bookmark.id + ' - ' + bookmark.title + ' - ' + bookmark.url); bookmarkEntries = bookmarkEntries.concat([bookmark.id + ' - ' + bookmark.title + ' - ' + bookmark.url]); // why are bookmarks not being added to global ?? if (bookmark.children) printBookmarks(bookmark.children); }); } function setBookmarkData() { bookmarkEntries = [] chrome.bookmarks.getTree(function(bookmarks) { printBookmarks(bookmarks); }); alert(bookmarkEntries) // comes up as empty array ??? }


LinkBack URL
About LinkBacks



Reply With Quote
