按照此处的教程,我无法删除文本。由于某种原因,当我单击 X 时,deleteThisPost() 永远不会被触发。我对代码所做的唯一其他更改是将任务替换为发布。
http://tutorial-viewer.meteor.com/tutorial/4/react
// Post component - represents a single todo item
Post = React.createClass({
propTypes: {
// This component gets the post to display through a React prop.
// We can use propTypes to indicate it is required
post: React.PropTypes.object.isRequired
},
toggleChecked() {
Posts.update(this.props.post._id, {
$set: {checked: ! this.props.post.checked}
});
},
deleteThisPost() {
Posts.remove(this.props.post._id);
console.log("Deleted" + this.props.post._id);
},
render() {
const postClassName = this.props.post.checked ? "checked" : "";
return (
<li className={postClassName}>
<button className="delete" onclick={this.deleteThisPost}>
×
</button>
<input type="checkbox"
readOnly={true}
checked={this.props.post.checked}
onClick={this.toggleChecked} />
<span className="text">{this.props.post.text}</span>
</li>
);
}
});
最佳答案
不确定这是否是唯一的问题,但“onclick”应该是“onClick”
<button className="delete" onclick={this.deleteThisPost}>
关于javascript - React Meteor 教程无法删除 this.props.post._id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31634645/