简体   繁体   English

React Meteor教程无法删除this.props.post._id

[英]React Meteor Tutorial can't remove this.props.post._id

Following the tutorial here I can't delete the text. 遵循本教程之后,我无法删除文本。 For some reason the deleteThisPost() is never fired when I click the X. The only other change I have made to the code is to replace task to post. 由于某些原因,当我单击X时,永远不会触发deleteThisPost()。我对代码所做的唯一其他更改是替换要发布的任务。

http://tutorial-viewer.meteor.com/tutorial/4/react 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}>
        &times;
        </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}>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM