我正在浏览此tutorial,并且在我更改了记录组件并在两个DOM渲染之间添加了React.createElement RecordForm, handleNewRecord: @addRecord
之前一直很好。似乎干扰并阻止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
是什么给出了?
答案 0 :(得分:0)
看起来我在handleChange之前有一个非预期的空间。在每个函数之间添加换行符解决了它。 >:/