【发布时间】:2015-09-21 17:53:36
【问题描述】:
我有两个类,officerModals 和 OfficerPhoto,officerModals 应该将数据传递给 OfficerPhoto。但是,当我尝试注销OfficerPhoto 中的数据时,我只会得到undefined。我一直在关注 Reacts 的教程,但我不知道哪里出了问题。有人可以帮忙吗?
reactReady = ->
officerModals = React.createClass
getInitialState: ->
{data: []}
componentDidMount: ->
$.ajax
url: this.props.url
dataType: 'json'
cache: false
success:((data) ->
@setState data: data
# console.log data <- this logs the correct data
console.log @state.data.officers <- so does this
).bind(this)
render: ->
React.createElement 'div', { className: 'photos' }, React.createElement(OfficerPhoto, data: @state.data.officers)
OfficerPhoto = React.createClass
render: ->
React.createElement 'h1', {className: 'yes'}
console.log 'test'
console.log @props #<- this returns undefined
React.render React.createElement(officerModals, {url: "officers.json"}), $('#officerPics').get 0
$(document).ready reactReady
$(document).on 'page:load', reactReady
编辑:我在登录 @props 之前卡在了一个字符串中,并且我取消了 @state.data.officers 的注释。似乎officerPhoto 是在officerModals 之前渲染的——我该如何解决这个问题?
【问题讨论】:
标签: javascript coffeescript reactjs