gpt4 book ai didi

javascript - 未捕获的类型错误 : this. props.onDelete 不是函数 reactjs

转载 作者:搜寻专家 更新时间:2023-11-01 05:30:19 25 4
gpt4 key购买 nike

The problem occurs when i'm trying to delete a to do list,onDelete is not a function.Full code is here in the git.Thanks

var TodoList = React.createClass({
onDelete : function(key){
console.log('remove here');
},
render: function() {
var createItem = function(itemText,i) {
return (
<TodoListItem onDelete={this.remove} 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)}
</li>
</ul>
)
}
});




var TodoListItem = React.createClass({
remove : function(key){
console.log('test:',key);
console.log('that.props',this);
this.props.onDelete();
},
render : function(){
return(
<li className="collection-item">
<div>{this.props.children}
<a onClick=
{this.remove.bind(this,this.props.index)} href="#" className="secondary-content"><i className="material-icons">delete</i>
</a>
</div>
</li>
)
}
});

最佳答案

问题出在线路上

onDelete={this.remove}

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

关于javascript - 未捕获的类型错误 : this. props.onDelete 不是函数 reactjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31817631/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com