【发布时间】:2021-11-27 22:36:46
【问题描述】:
老实说,我不知道为什么不工作,它甚至没有意义,而且它在你能发现一些我看不到的东西之前就开始工作了。
我正在使用类型号将一些数据更新到 Firebase,但即使我使用的是输入类型号,它也被存储为字符串,但由于某种原因它似乎无法正常工作,代码如下:
//Firebase set
const [precio, setPrecio] = useState();
const register = (e) => {
e.preventDefault();
const docRef = db.collection('productos_AIB').doc(docId);
docRef.get().then((doc) => {
if (doc.exists)
{
window.alert("Ya existe ese producto")
}
else {
docRef.set({
descripcion: descripcion,
tipo: tipo,
grado: grado,
precio: parseFloat(precio).toFixed(2),
cantidad: cantidad,
necesita: necesita,
id: docRef.id
}).then((r) => {
window.alert("Producto agregado")
})}
})
}
//Input
<input
onChange = {(e) => {setPrecio(e.target.valueAsNumber);}}
type = 'number'
pattern = "[0-9]*"
requiredplaceholder="Precio"
/>
如果您需要其他内容,请告诉我,IDK 为什么它停止工作,也许我在没有注意到的情况下更改了某些内容,但我无法发现错误。
更新忘记添加它在 Firestore 中的外观图片:
【问题讨论】:
标签: reactjs firebase google-cloud-platform google-cloud-firestore