ProjetRIOT/components/search.riot

50 lines
1.5 KiB
Plaintext

<search>
<label>
<input oninput={searchF} type="input" placeholder= {state.formation}>
<div id="list-formations">
<ul>
<li each={item in this.state.items}>
<a href={item.path} target="_blank">{item.name}</a>
<span>{item.count}</span>
</li>
</ul>
</div>
</label>
<script>
async function formation(){
let result = await fetch("https://data.enseignementsup-recherche.gouv.fr/api/records/1.0/search/?dataset=fr-esr-parcoursup&q=&sort=tri&facet=fili&timezone=Europe%2FBerlin")
let resultats = await result.json()
let table = resultats["facet_groups"][0]["facets"]
return table
}
export default function search(){
return {
onBeforeMount(props, state) {
// initial state
this.state = {
formation: props.formation,
items: null
}
formation().then((response) => {
this.update({
items: response
})
})
console.log(this.state.items)
},
searchF(){
formation().then((response) => {
this.update({
items: response
})
})
console.log(this.state.items)
}
}
}
</script>
</search>