这是我的文本所在的节点状态数组
https://gyazo.com/bcaf5a92389289c5923d40bb6aa1f1f7
我想在不同节点的编辑表单中重新加载它,我遇到的问题是,当我尝试使用编辑按钮加载表单时,不同节点的表单中数据不同
<form>
{
this.state.texts.map((text, index) => (
<div className="shareholder" key={index}>
<input
type="text"
name="abc"
onChange={(e) => this.handleChange(e, index)}
defaultValue={text.textid}
/>
<input
type="text"
name="id"
onChange={(e) => this.handleChange(e, index)}
defaultValue={this.state.nodeid}
/>
<button
type="button"
onClick={() => this.handleRemove(index)}
className="small"
>
-
</button>
</div>
))}
<button
type="button"
onClick={(e) => this.addProcess(e)}
className="small"
>
Add Process
</button>
<button
type="button"
onClick={(e) => this.saveProcess(e)}
className="small"
>
Edit
</button>
</form>
</Modal>
这是我的“添加表单”功能,可以处理文本的更改和删除功能
addProcess() {
this.setState({ texts: [...this.state.texts, { textid: "", text: "" }] });
}
handleChange(e, index) {
//eslint-disable-next-line
this.state.texts[index] = e.target.value
this.setState({ texts: this.state.texts })
}
handleRemove(index) {
this.state.texts.splice(index, 1)
this.setState({ texts: this.state.texts })
}