您好,我正在嘗試更新表中的行值 (React Ant Ui),它在我使用靜態(tài)數(shù)據(jù)時(shí)有效。比如我的靜態(tài)數(shù)據(jù)表數(shù)據(jù)是[ { "questionNumber": "", "questionType": "", "marks": "", "numberOfOptions": "", "correctOptions": "", }, { "questionNumber": "", "questionType": "", "marks": "", "numberOfOptions": "", "correctOptions": "", }, ]我使用以下方法更新行數(shù)據(jù)- const onInputChange: any = (key, index) => ( e: React.ChangeEvent<HTMLInputElement> ) => { const newData = [...tableData]; newData[index][key] = (e); setTableData(newData); };如果我想更新它的標(biāo)記,index 1它工作得很好。但是我需要更新動(dòng)態(tài)數(shù)據(jù)。我遵循了這種方法const [tableData, setTableData] = useState<any>([]);然后單擊按鈕,我將動(dòng)態(tài)數(shù)組值推送到表數(shù)據(jù)中,就像這樣setTableData(Array(3).fill(newObj))newObj價(jià)值在哪里 const newObj = { "questionNumber": "", "questionType": "", "marks": "", "numberOfOptions": "", "correctOptions": "", }但是現(xiàn)在我面臨一個(gè)問(wèn)題,如果我想改變 的值marks,它會(huì)更新所有的索引marks如何像靜態(tài)數(shù)組一樣更新此動(dòng)態(tài)數(shù)組的單個(gè)索引值?
JavaScript 數(shù)組對(duì)象值更新 (React)
慕斯709654
2023-04-20 17:10:27