如何更新我剛剛編輯到 firebase 的值?到目前為止,這是我從 editRow 了解到的(如果我錯了,請糾正我)
內部資料網格
//Enable edit mode for row and not cell
editMode="row"
//any update you do in the row is stored in this variable so when you finish it overrides
//w/e you had there with editRowsModel value
editRowsModel={editRowsModel}
//Calls for the function that will be handeling the updates and the all the updates into "model"
onEditRowsModelChange={handleEditRowsModelChange}
//For Double Click Control
//(That way if uses double click by mistake it doesn't enable editMode)
onCellDoubleClick={(params, event) => {
if (!event.ctrlKey) {
event.defaultMuiPrevented = true;
}
}}
常量
//Variable that will hold the edited variable
const [editRowsModel, setEditRowsModel] = React.useState({});
//Edit function
const handleEditRowsModelChange = React.useCallback((model) => {
setEditRowsModel(model);
}, []);
現在在 Edit 函式中,我想編輯該行,但如何更新到 firebase ?就像我有這個:
const [editRowsModel, setEditRowsModel] = React.useState({});
const handleEditRowsModelChange = React.useCallback((model) => {
setEditRowsModel(model);
console.log(model.uid)
/*
estudiantes.filter( x => {
const temporalQuery = db.collection("usuarios").doc(user.uid).collection("estudiantes").doc(x.uid);
temporalQuery.update({
nombre: model.nombre,
colegio: model.colegio,
grado: model.grado
})
})
*/
}, []);
但是這不起作用,因為我看不到模型中的各個值,因為它只是說“未定義”,否則這會起作用。如何獲得模型的各個值?
并且因為未定義,當我嘗試該代碼時我會得到一個錯誤

歡迎任何幫助/提示。
模型如何記錄
console.log(model)
console.log(model.name)
console.log(model[0].name)

uj5u.com熱心網友回復:
我不確定我是否正確理解您的問題,但如果您想訪問編輯行資料,您可以這樣做:
const [editRowsModel, setEditRowsModel] = React.useState({});
const [editRowData, setEditRowData] = React.useState({});
const handleEditRowsModelChange = React.useCallback(
(model) => {
const editedIds = Object.keys(model);
// user stops editing when the edit model is empty
if (editedIds.length === 0) {
alert(JSON.stringify(editRowData, null, 4));
// update on firebase
} else {
setEditRowData(model[editedIds[0]]);
}
setEditRowsModel(model);
},
[editRowData]
);
console.log(editRowData);
return (
<div style={{ height: 300, width: "100%" }}>
<DataGrid
rows={rows}
columns={columns}
editMode="row"
editRowsModel={editRowsModel}
onEditRowsModelChange={handleEditRowsModelChange}
onCellDoubleClick={(params, event) => {
if (!event.ctrlKey) {
event.defaultMuiPrevented = true;
}
}}
/>
</div>
);
現場演示
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/322644.html
標籤:反应 火力基地 谷歌云firestore 数据网格 材质-ui
上一篇:靜態庫是否與版本無關?
