对于类似的情况,我尝试遵循其他一些答案,但是我无法解决。有人可以指出问题吗?
export default class Rescheduler extends Component {
constructor(props) {
super(props);
this.state = {
posts: [],
reschedule: {
post_id: null,
post_url: '',
scheduled_at: moment(),
post_rescheduled: false
},
show_loader: false
}
}
unschedulePost(index)
{
console.log('index:', index);
}
render(){
let posts = this.state.posts.map(function(post, index){
let dateTime = new Date(post.scheduled_at);
let scheduledAt = moment(dateTime).format("DD-MM-YYYY HH:mm");
return <tr key={index}>
<td>
<a href={post.details.url} target="_blank">
<img src={post.details.thumbnail} className="img-thumbnail" width="75" />
</a>
</td>
<td>
<h4><a href={post.details.url} target="_blank">{post.details.title}</a></h4>
</td>
<td>
<strong>{scheduledAt}</strong>
</td>
<td className="text-center">
<button
onClick={this.unschedulePost.bind(this, index)}
id="schedule-post-btn"
className="btn btn-danger btn-xs" >
<span className="glyphicon glyphicon-trash"></span>
</button>
</td>
</tr>
});
<div>
<h2>Scheduled Posts</h2>
<table className="table table-striped scheduled-posts-table">
<thead>
<tr>
<th>Thumbnail</th>
<th>Title</th>
<th>Scheduled At:</th>
<th>Unschedule</th>
</tr>
</thead>
<tbody>{posts}</tbody>
</table>
</div>
}
}
当我尝试单击“计划外按钮”时,收到以下消息:
TypeError:无法读取未定义的属性“ unschedulePost”
有人可以告诉我问题是什么以及如何解决? 我知道互联网上也有人问过类似的问题,但是我无法正常工作:/