Am trying to fill a file panel with all the files names in the filesList which is just an array.
When i run my app, the filesList content is loaded and at the console it shows that the list contains file objects but no elements get append to the listGroup in the DOM. I have tried to log the ==entries== but nothing gets logged. This is confusing because in the console, the filesList array contains the file Objects and filesList.length > 0 when i log it to the console.
import { FILE_PANEL } from "../../app.js";
export function fillFilePanel(filesList)
{
console.log(filesList);
for (let i = 0; i < filesList.length; i++) {
let entries = filesList[i]
if (entries.isDirectory == true) {
FILE_PANEL.append(`<button id="F${entries.name}" type="button" class="list-group-item list-group-item-action" key="folder" data-toggle="#F${entries.name}Group">${entries.name}</button>
<ul class="list-group" id="F${entries.name}Group">
</ul>`);
let parentDir = entries.name + '/';
// showSubFolder(parentDir)
}
else {
FILE_PANEL.append(`<button type="button" class="list-group-item list-group-item-action">${entries.name}</button>`);
}
}
}
Code in ==MainFs.js==
import { fillFilePanel } from "./ui/sideBar.js"
{
//...some code that does other things
let filesList = [];
listDir().then(val => (val.forEach((f) => { filesList.push(f);
})));
fillFilePanel(filesList)
}
/**
* Read the local storage and fill the sidebar with files in it
**/
export function listDir(url = '') {
return new Promise(function(res, reject) {
let path = cordova.file.externalRootDirectory + url
console.log();
window.resolveLocalFileSystemURL(path,
function(fs) {
const reader = fs.createReader();
reader.readEntries(function(entries) {
res(entries)
}, (rej) => { return rej });
}, (rej) => { return rej });
});
}
Sample output when i console.log(filesList)
[{"isFile":false,"isDirectory":true,"name":".face","fullPath":"/.face/","filesystem":"<FileSystem: sdcard>","nativeURL":"file:///storage/emulated/0/.face/"},{"isFile":false,"isDirectory":true,"name":".audio_param","fullPath":"/.audio_param/","filesystem":"<FileSystem: sdcard>","nativeURL":"file:///storage/emulated/0/.audio_param/"},{"isFile":false,"isDirectory":true,"name":"Music","fullPath":"/Music/","filesystem":"<FileSystem: sdcard>","nativeURL":"file:///storage/emulated/0/Music/"},{"isFile":false,"isDirec ...}]
The app uses cordova file plugin to read files.