我的文本文件数是动态的,并且将值保存到数组中的那些文本字段中。起初,这些值使用不可变性助手填充了来自服务器的数据,但是当我要编辑文本文件时,它不会改变。当我打印state的值时,值会更改,但文本字段不会更新。
handleWordChange = (wordID, e) => {
let me = this;
me.setState(update(me.state, {finWords: {[wordID]: {$set: e.target.value}}}), () => console.log(me.state.finWords));
};
for (let i = 0; i < data.length; i++)
for (let word in data[i])
if (data[i].hasOwnProperty(word)) {
me.setState(update(me.state, {finWords: {$push: [data[i][word]]}}));
rows.push(
<Card key={i}>
<CardContent>
<TextField
name={"fin-word"+i}
value={me.state.finWords[i]}
onChange={(e) => me.handleWordChange(i, e)}
/>
</CardContent>
</Card>
);
}