0

我正在阅读本教程,在我更改 Records 组件并React.createElement RecordForm, handleNewRecord: @addRecord在两个 DOM 渲染之间添加之前一直很好。似乎完全干扰和阻止 DOM 渲染。

这是组件:

@Records = React.createClass
  getInitialState: ->
    records: @props.data
  getDefaultProps: ->
    records: []
  addRecord: (record) ->
    records = @state.records.slice()
    records.push record
    @setState records: records
  render: ->
    React.DOM.div
      className: 'records'
      React.DOM.h2
        className: 'title'
        'Records'
      React.createElement RecordForm, handleNewRecord: @addRecord
      React.DOM.hr null
      React.DOM.table
        className: 'table table-bordered'
        React.DOM.thead null,
          React.DOM.tr null,
            React.DOM.th null, 'Date'
            React.DOM.th null, 'Title'
            React.DOM.th null, 'Amount'
        React.DOM.tbody null,
          for record in @state.records
            React.createElement Record, key: record.id, record: record

控制台错误显示“未捕获的 ReferenceError:RecordForm 未定义”。哪个,是的,我这样做了,它是:

@RecordForm = React.createClass
 bla bla bla bla
 handleChange: (e) ->
   name = e.target.name
   @setState "#{ name }": e.target.value
 handleSubmit: (e) ->
    e.preventDefault()
    $.post '', { record: @state }, (data) =>
      @props.handleNewRecord data
      @setState @getInitialState()
    , 'JSON'
  render: ->
    React.DOM.form
     bla bla bla bla

是什么赋予了?

4

1 回答 1

0

看起来我在 handleChange 之前有一个意想不到的空间。在每个函数之间添加换行符解决了它。>:/

于 2016-05-08T22:20:17.847 回答