1
0
Fork 0
mirror of synced 2024-07-04 14:01:27 +12:00
budibase/packages/standard-components/src/List.svelte

36 lines
699 B
Svelte
Raw Normal View History

2020-06-03 10:26:06 +12:00
<script>
import { onMount } from "svelte"
export let _bb
export let model
let headers = []
let store = _bb.store
let target
async function fetchData() {
if (!model || !model.length) return
2020-06-19 03:59:31 +12:00
const FETCH_RECORDS_URL = `/api/views/all_${model}`
2020-06-03 10:26:06 +12:00
const response = await _bb.api.get(FETCH_RECORDS_URL)
if (response.status === 200) {
const json = await response.json()
_bb.attachChildren(target, {
hydrate: false,
context: json,
})
} else {
throw new Error("Failed to fetch records.", response)
}
}
$: if (model) fetchData()
onMount(async () => {
await fetchData()
})
</script>
2020-07-08 08:29:20 +12:00
<section bind:this={target} />