用对象数组填充选择
我的firebase有一个变量的结果:
[
{
"value": "CHProNd9BGYznrEr0u43",
"label": "Jean"
},
{
"value": "Huo0mofwJGKx2uEd9467",
"label": "aaa"
},
{
"value": "IO5w6WstNngCNyKRneYg",
"label": "African"
}
]
我想通过firebase的呼叫来获得此结果:
export async function getCoupeurs() {
let getCoupeurFromFirebase = [];
const coupeursRef = collection(db, "coupeurs");
getDocs(coupeursRef).then(snapshot => {
snapshot.forEach(doc => {
getCoupeurFromFirebase.push({
value: doc.id,
label: doc.data().nom,
});
});
});
return getCoupeurFromFirebase;
}
我想填写此选择输入:
<select>
{
coupeurs.map(coupeur => (
<option key={coupeur.value} value={coupeur.value}>{coupeur.label}</option>
))
}
</select>
但是我在屏幕上什么也没有错误,没有错误,您能帮我通过最好的方式? [更新] codepen.io上的代码,我认为问题是从数据库中呼吁数据,有一种方法可以告诉我我想等待结果,然后再将数据发送到我的组件?
https://codepen.io/lbain/lbain/pen/pen/pen/enpzbz
<select>
{
coupeurs.map(coupeur => (
<option>{coupeur.label}</option>
))
}
</select>
谢谢。
I have this result from my firebase in a variable :
[
{
"value": "CHProNd9BGYznrEr0u43",
"label": "Jean"
},
{
"value": "Huo0mofwJGKx2uEd9467",
"label": "aaa"
},
{
"value": "IO5w6WstNngCNyKRneYg",
"label": "African"
}
]
I get this result with this call to firebase :
export async function getCoupeurs() {
let getCoupeurFromFirebase = [];
const coupeursRef = collection(db, "coupeurs");
getDocs(coupeursRef).then(snapshot => {
snapshot.forEach(doc => {
getCoupeurFromFirebase.push({
value: doc.id,
label: doc.data().nom,
});
});
});
return getCoupeurFromFirebase;
}
and i want to fill this select input :
<select>
{
coupeurs.map(coupeur => (
<option key={coupeur.value} value={coupeur.value}>{coupeur.label}</option>
))
}
</select>
but i have nothing on my screen and no error, can you help me to do this by the best way ?
[updated]
The code on codepen.io , that work so i think the problem is the call for data from database there is a way to tell that i want to wait the result before send the data to my component ?
https://codepen.io/lbain/pen/ENpzBZ
<select>
{
coupeurs.map(coupeur => (
<option>{coupeur.label}</option>
))
}
</select>
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论