React Meteor Tutorial无法删除this.props.post._id

时间:2015-07-26 07:20:56

标签: javascript meteor reactjs

按照这里的教程,我无法删除文本。出于某种原因,当我单击X时,从不触发deleteThisPost()。我对代码所做的唯一其他更改是将任务替换为post。

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>
    );
  }
});

1 个答案:

答案 0 :(得分:2)

不确定这是否是唯一的问题,但是&#34; onclick&#34;应该是&#34; onClick&#34;在

<button className="delete" onclick={this.deleteThisPost}>