Javascript 未捕获类型错误:this.props.onDelete不是函数

Javascript 未捕获类型错误:this.props.onDelete不是函数,javascript,git,reactjs,Javascript,Git,Reactjs,当我试图删除一个待办事项列表时会出现问题,onDelete不是一个函数。完整的代码在git中。谢谢 var TodoList=React.createClass({ onDelete:功能(键){ console.log('remove here'); }, render:function(){ var createItem=函数(itemText,i){ 返回( {itemText} ); }; 返回( 待办事项清单 {this.props.items.map(createItem)}

当我试图删除一个待办事项列表时会出现问题,onDelete不是一个函数。完整的代码在git中。谢谢

var TodoList=React.createClass({
onDelete:功能(键){
console.log('remove here');
},
render:function(){
var createItem=函数(itemText,i){
返回(
{itemText}
);
};
返回(
  • 待办事项清单 {this.props.items.map(createItem)}
) } }); var TodoListItem=React.createClass({ 移除:功能(键){ log('test:',key); console.log('that.props',this); this.props.onDelete(); }, render:function(){ 返回(
  • {this.props.children}
  • ) } });
    问题来自线路

    onDelete={this.remove}
    

    未定义此删除函数。你的wnat在onDelete有什么事要做吗?如果没有,您可以删除
    this.props.onDelete()

    问题来自这一行

    onDelete={this.remove}

    改为

    onDelete={this.onDelete}


    所做的更改是
    {this.props.items.map(createItem)}
    {this.props.items.map(createItem,this)}


    状态变量是在TodoList类中定义的,所以要访问要删除的状态变量,我需要调用TodoList类函数。你能查一下github回购协议吗,谢谢
    onDelete={this.remove}
    
    var TodoList = React.createClass({
        remove : function(index){
            console.log('remove from here:',this.props.items);
            console.log('index:',index);
        },
        render: function() {
            var createItem = function(itemText,i) {
                return (
                    <TodoListItem onDelete={this.remove.bind(this,i)} index={i} key={i}>{itemText}
                    </TodoListItem>
                );
            };
            return(
                <ul id="staggered-test" className="collection 
                    with-header">
                    <li className="collection-header">
                        <h4>todo list</h4>
                        {this.props.items.map(createItem,this)}
                    </li>
                </ul>
            )
        }
    });
    
    var TodoListItem = React.createClass({
        render : function(){
            return(
                <li className="collection-item">
                    <div>{this.props.children}
                        <a onClick={this.props.onDelete} href="#" 
                        className="secondary-content">
                            <i className="material-icons">delete</i>
                        </a>
                    </div>
                </li>
            )
        }
    });