简体   繁体   English

如何以苗条的形式返回 Firestore 结果?

[英]How do I return firestore result in svelte?

How do you get the result from this in svelte into the page:你如何在页面中得到这个结果:

async function getCities(db) {
  const citiesCol = collection(db, 'cities');
  const citySnapshot = await getDocs(citiesCol);
  const cityList = citySnapshot.docs.map(doc => doc.data());
  return cityList;
}

Thanks to @voscausa I solved it.感谢@voscausa,我解决了它。 Had to use await https://svelte.dev/tutorial/await-blocks .不得不使用 await https://svelte.dev/tutorial/await-blocks

let cities = getCities();

{#await cities}
    <p>...waiting</p>
{:then cities}
  {#each cities as city}
      {city.name}
  {/each}
{:catch error}
    
{/await}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM