Reactjs 如何在React中编辑待办事项
我的问题是,当我点击编辑图标并编辑我的todo时,更新它。然后,编辑的todo在todo-list中显示新todo。新todo和旧todo(我已编辑)都显示在todo列表中。如何解决这个问题?如何在我编辑过的列表中显示待办事项?有人能帮我吗。 这是我的密码。。 todoApp.JSxReactjs 如何在React中编辑待办事项,reactjs,Reactjs,我的问题是,当我点击编辑图标并编辑我的todo时,更新它。然后,编辑的todo在todo-list中显示新todo。新todo和旧todo(我已编辑)都显示在todo列表中。如何解决这个问题?如何在我编辑过的列表中显示待办事项?有人能帮我吗。 这是我的密码。。 todoApp.JSx editTask:function(todo_id,newValue,todoStartDate,todoEndDate){ console.log(todo_id,newValue,todoSta
editTask:function(todo_id,newValue,todoStartDate,todoEndDate){
console.log(todo_id,newValue,todoStartDate,todoEndDate);
axios.post('/edittodos',{
todo_id:todo_id,
todo_text:newValue,
todo_start_at:todoStartDate,
todo_end_at:todoEndDate
}).then(function (response){
}).catch(function (error){
});
//how to display todo in list after editing todo
this.setState({
todos:[
{
todo_text:newValue,
todo_start_at:todoStartDate,
todo_end_at:todoEndDate
},
...this.state.todos,
]
});
},
jsx问题在于您的设置状态,您实际上是在添加一个todo,而不是替换它 喜欢吗
var todos = [...this.state.todos];
var index = todos.findIndex((todo) => todo.todo_id == todo_id)
todos[index].todo_text = newValue
todos[index].todo_start_at = todoStartDate
todos[index].todo_end_at=todoEndDate
this.setState({
todos
});
页面刷新后是否知道此错误语法错误:应为表达式,登录后得到“我重定向到todoApp”。我的网址是这样的。如果我用这个url刷新我的页面,我会出错。你怎么重定向,你能添加代码吗?你还有其他问题吗?syntaxError。。!不,我有另一个问题。所以我正在努力解决这些问题