Javascript Props值未显示在函数ReactJS的渲染顶部

Javascript Props值未显示在函数ReactJS的渲染顶部,javascript,reactjs,Javascript,Reactjs,然而,this.props.NotesAll从另一个组件检索对象,并在render()方法下显示对象的to,但当我试图使用函数render顶部的this.props.NotesAll来处理这些对象时,我试着用控制台检查函数的值,它总是说是未定义的狗屎。所以请帮助我,忍者到底是怎么回事 在这里,您可以查看这些代码 export default class EditNotes extends Component { constructor(props) { super(pro

然而,
this.props.NotesAll
从另一个组件检索对象,并在render()方法下显示对象的to,但当我试图使用函数render顶部的
this.props.NotesAll
来处理这些对象时,我试着用控制台检查函数的值,它总是说是未定义的狗屎。所以请帮助我,忍者到底是怎么回事

在这里,您可以查看这些代码

export default class EditNotes extends Component {
    constructor(props) {
        super(props);
        this.state ={};
    }


    handleEdit() {
        console.log(this + ' Clicked on That ');
    }

//Here it's throwing error when I'm trying to click and console. the problem is here. i want this.props.NotesAll value here also to finding elements from objects
    handleDelete(id) {
        let Notes = this.props.NotesAll;
        console.log(Notes)
    }

    render() {
        let noteItems;
//这个道具在这里都很好用

        if (this.props.NotesAll) {
            noteItems = this.props.NotesAll.map( Note => {
                return(
                    <li key={Note.id}>{Note.body}
                    <button onClick={this.handleEdit.bind(Note.id)} className="btn btn-primary btn-sm">Edit</button>
                    <button onClick={this.handleDelete.bind(Note.id)} className="btn btn-danger btn-sm">Delete</button></li>
                    );
            });
        }
        return(
            <div className="col-md-4">
                <h3 className="header-ttile">Current Notes:</h3>
                <ul className="note-item-wrapper">
                {noteItems}
                </ul>
            </div>
            );
    }
}
if(this.props.NotesAll){
noteItems=this.props.NotesAll.map(注意=>{
返回(
  • {Note.body} 编辑 删除
  • ); }); } 返回( 当前注释:
      {noteItems}
    ); } }
    如果以错误的方式定义绑定,则第一个参数将是要绑定到的上下文

    使用以下命令:

    <button onClick={this.handleDelete.bind(this, Note.id)}
    
    此参数:

    要作为此参数传递给目标函数的值 调用绑定函数时


    然后尝试访问HandDelete函数中的this.notes。我不确定,因为我也不是react忍者,但我认为它应该这样工作

    我们对此没有任何问题,它工作得很好。我只需要在handleDelete和handleEdith两个位置上都有
    这个.props.NotesAll的所有对象。它抛出了未定义的内容。@mayank可以用我建议的方式编写它,因为当你绑定
    时,只有你才能访问
    handleDelete
    方法中正确的
    (上下文)。天哪,你在开玩笑吗?它工作得很好!!!谢谢你,伙计。3个小时后我就开始胡闹了。
    fun.bind(thisArg[, arg1[, arg2[, ...]]])
    
    constructor(props) {
        super(props);
        this.state ={};
        this.notes = props.notesAll;
        this.handleDelete = this.handleDelete.bind(this);
    }