0

我有动态数量的文本文件,并将值保存到数组中的这些文本字段中。起初,这些值使用不变性助手从服务器中填充数据,但是当我想编辑文本文件时,它不会改变。当我打印状态值时,值已更改但文本字段未更新。

    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>
              );
           }
4

0 回答 0