【发布时间】:2020-08-21 22:30:12
【问题描述】:
state = {one_book : []}
updateName = event =>{
var newvalue = event.target.value
const id = 1;
let one_book = this.state.one_book; // create the copy of state array
one_book[1] = newvalue; //new value
this.setState({ one_book });
console.log(this.state.one_book)
}
这里的新值是我们要更改为json文件的更新值。我想用这个新名称更新 id =1 的书名,或者用 one_book 更新 json 文件中的整个对象。这些更改应该反映在原始 json 文件中
I have to update this state into json file with the respective id.
Here is my json file
[
{
"id": 1,
"bookname": "Physics",
"price": 600,
"author": "ABC",
"pages": 567,
"category" : "School Books"
},
{
"id": 2,
"bookname": "Let Us C",
"price": 1300,
"author": "XYZ",
"pages": 1267,
"category" : "Technical"
}
]
【问题讨论】:
标签: json reactjs state form-data insert-update