我正在阅读本教程,在我更改 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
是什么赋予了?