ondata
Description
Triggered when the widget needs to load tasksIt allows integration with any data source, such as REST APIs
Usage
ondata?: (value: string | number) => Promise<{
id?: string | number;
content: string;
status?: number;
}[]> | {
id?: string | number;
content: string;
status?: number;
}[];
Parameters
The ondata
callback receives a single argument:
value
– (required) the identifier of the task stream to be loaded
The callback must return either:
- an array of task objects, or
- a Promise resolving to an array of task objects
Each task object may include:
id
– (optional) a unique identifier of the taskcontent
– (required) the text content of the taskstatus
– (optional) the status of the task that can be 0 for incomplete and 1 for complete
Examples
Loading tasks through REST helper
<script>
import { RestURL } from "@svar-ui/lib-data-provider";
import { Tasklist } from '@svar-ui/svelte-tasklist';
const url = new RestURL("https://some.com/api/tasks");
</script>
<Tasklist on:data={v => url.get(v)} />
Converting ID of task's stream to data
<script>
import { Tasklist } from '@svar-ui/svelte-tasklist';
const ondata = (v) => {
return fetch(`/api/tasks/${v}`).then(r => r.json());
};
</script>
<Tasklist value={1} {ondata} />