【已解决】React 调用函数竟然不对,提示这个函数undefined

goToDetail(){
console.log("看看能出来吗?")
}
renderComment({name,author,uploadTime,description,category,sraID}){
switch(category){
case"0":return"other";
case"1":return"project";
case"2":return"paper";
case"3":return"book";
case"4":return"certificate";
case"5":return"patent";
case"6":return"picture";
}
return(
{name}

{author}
-
{uploadTime}

描述:{description}

);
}
render(){
if(this.state.contents){
return(
{this.state.contents.map(this.renderComment)}
)
}else{
return(
)
}
}
不知道什么原因,求大神解答。。。
杨魅力
浏览 723回答 2
2回答

慕码人2483693

手动绑定下thisconstructor(){super();this.renderComment=this.renderComment.bind(this);}用箭头函数renderComment=()=>{}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript