React 未在提交处理程序中找到 <input/> 值

React not Finding <input/> Value in Submit Handler

这是我的 React class:

var React = require('bower.js').React;
var paper = require('bower.js').paper;

var NotePanel = React.createClass({
  getInitialState: function() {
    return {
      noteToAdd: ""
    };
  },
  setNoteToAdd: function(event) {
    event.preventDefault();
    var note = this.refs.noteToAdd.value;
    console.log(this.refs.noteToAdd.value);
    this.setState({
        noteToAdd: note
    });
  },
  render: function() {
    return (
      <div>
        <form onSubmit={this.setNoteToAdd}>
          <input ref="noteToAdd" type="text" />
          <input type="submit" value="Add Note" />
        </form>
      </div>
    );
  }
});

module.exports = NotePanel;

它紧跟 tutorial16.js here 中的代码(大于页面的一半)。

然而,行

console.log(this.refs.noteToAdd.value);

向控制台打印未定义。我不确定我错过了什么。 ref 似乎设置正确。渲染代码与教程中的非常相似。但是在点击处理功能中,我无法像教程中那样访问 input refvalue。这是为什么?

尝试一下;

this.refs.noteToAdd.getDOMNode().value

v0.12.0 中使用 this.refs.noteToAdd.getDOMNode().value

v0.13.0 中使用 React.findDOMNode(this.refs.noteToAdd).value

v0.14.0 中使用 this.refs.noteTOAdd.value