by drakinite » Sun Jan 30, 2022 2:52 pm
Yes; you need to asynchronously wait for the list to load via
whenLoaded(). I wrote some extra documentation on it and it should be up on the API docs site soon. In the meantime:
Tracklist class (list of Tracks). In most cases, when you request a new Tracklist (for example, with uitools.getSelectedTracklist() or playlist.getTracklist()), the list will be returned before it has been populated with its contents. To resolve this, you must asynchronously wait for it to be loaded. You can do this either with
Promise.then() or with
async/await:
Code: Select all
// Method 1
var list = uitools.getSelectedTracklist();
list.whenLoaded()
.then(function () {
// do your operations on the list
});
// Method 2
async function myFunc() {
var list = uitools.getSelectedTracklist();
await list.whenLoaded();
// do your operations on the list
}
myFunc();
if you change your function definition to
async function clearFields(){ and add
await list.whenLoaded(); after
let list = uitools.getSelectedTracklist();, it'll work.
Yes; you need to asynchronously wait for the list to load via [b]whenLoaded()[/b]. I wrote some extra documentation on it and it should be up on the API docs site soon. In the meantime:
Tracklist class (list of Tracks). In most cases, when you request a new Tracklist (for example, with uitools.getSelectedTracklist() or playlist.getTracklist()), the list will be returned before it has been populated with its contents. To resolve this, you must asynchronously wait for it to be loaded. You can do this either with [url=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then]Promise.then()[/url] or with [url=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function]async/await[/url]:
[code]// Method 1
var list = uitools.getSelectedTracklist();
list.whenLoaded()
.then(function () {
// do your operations on the list
});
// Method 2
async function myFunc() {
var list = uitools.getSelectedTracklist();
await list.whenLoaded();
// do your operations on the list
}
myFunc();[/code]
if you change your function definition to [b]async function clearFields(){[/b] and add [b]await list.whenLoaded();[/b] after [b]let list = uitools.getSelectedTracklist();[/b], it'll work.