Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/27.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 ';TypeError:无法读取属性';内部法';未定义的';,当我限定了上下文_Reactjs_React Props_Mern - Fatal编程技术网

Reactjs ';TypeError:无法读取属性';内部法';未定义的';,当我限定了上下文

Reactjs ';TypeError:无法读取属性';内部法';未定义的';,当我限定了上下文,reactjs,react-props,mern,Reactjs,React Props,Mern,我正在使用react进行一个小的初学者项目,我很难将方法传递给子组件。解决方案是不绑定上下文,这是我做的(可能是错误的)。 有人知道如何解决这个问题吗? 该应用程序是一个简单的todo管理应用程序,其中我有一个todo表作为父组件,还有几个todo作为行/子组件。我试图传递给每个todo的方法是一种重新排列整个表的方法。代码如下: import { Link } from 'react-router-dom'; import axios from 'axios'; import React, {

我正在使用react进行一个小的初学者项目,我很难将方法传递给子组件。解决方案是不绑定上下文,这是我做的(可能是错误的)。 有人知道如何解决这个问题吗? 该应用程序是一个简单的todo管理应用程序,其中我有一个todo表作为父组件,还有几个todo作为行/子组件。我试图传递给每个todo的方法是一种重新排列整个表的方法。代码如下:

import { Link } from 'react-router-dom';
import axios from 'axios';
import React, { Component } from 'react';
import Todo from './Todo';

export default class TodosList extends Component {

constructor(props) {
    super(props);
    this.updateComponent = this.updateComponent.bind(this);

    this.state = {todos: []};
}

componentDidMount() {
    axios.get('http://localhost:4000/todos/')
        .then(response => {
            this.setState({ todos: response.data });
        })
        .catch(function (error){
            console.log(error);
        })
}

updateComponent = () => {
    this.forceUpdate();
}

render() {
    return (
        <div>
            <h3>Todos List</h3>
            <table className="table table-striped" style={{ marginTop: 20 }} >
                <thead>
                    <tr>
                        <th>Description</th>
                        <th>Responsible</th>
                        <th>Priority</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                    {
                        this.state.todos.map(function(currentTodo, i){
                            return <Todo todo={currentTodo} updateParent={this.updateComponent} key={i} />;
                        })
                    }
                </tbody>
            </table>
        </div>
    )
}
从'react router dom'导入{Link};
从“axios”导入axios;
从“React”导入React,{Component};
从“/Todo”导入Todo;
将默认类导出到DoList扩展组件{
建造师(道具){
超级(道具);
this.updateComponent=this.updateComponent.bind(this);
this.state={todos:[]};
}
componentDidMount(){
axios.get()http://localhost:4000/todos/')
。然后(响应=>{
this.setState({todos:response.data});
})
.catch(函数(错误){
console.log(错误);
})
}
updateComponent=()=>{
这个.forceUpdate();
}
render(){
返回(
待办事项清单
描述
负责的
优先
行动
{
this.state.todos.map(函数(currentTodo,i){
返回;
})
}
)
}
}