Skip to main content

Serializing data

The widget API allows getting the current file structure as a plain array with the possibility to parse it back to get the same view.

To do this, you need to apply the api.serialize() method by passing any path as an id and you will get a plain array of all files and folders in this directory. The default id is "/" which will return the whole structure.

<script>
import { getData, getDrive } from "./common/data";
import { Filemanager } from "wx-svelte-filemanager";

const init = (api) => {
console.log(api.getFile("/Code/Button.svelte"));

const serializedData = api.serialize();
console.log(serializedData);

// to show the serialized data
setTimeout(() => {
api.exec("provide-data", {
parent: "/",
data: serializedData,
});
}, 2000);

console.log(api.serialize("/Music"));
}
</script>

<Filemanager data={getData()} drive={getDrive()} {init} />

Related articles: api.exec()

Related samples: API calls