Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何在React中编辑待办事项_Reactjs - Fatal编程技术网

Reactjs 如何在React中编辑待办事项

Reactjs 如何在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

我的问题是,当我点击编辑图标并编辑我的todo时,更新它。然后,编辑的todo在todo-list中显示新todo。新todo和旧todo(我已编辑)都显示在todo列表中。如何解决这个问题?如何在我编辑过的列表中显示待办事项?有人能帮我吗。 这是我的密码。。 todoApp.JSx

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。。!不,我有另一个问题。所以我正在努力解决这些问题