无法在 React-0.13.3 CJSX 代码中读取 属性

Cannot read a property in React-0.13.3 CJSX code

我正在开发一个 react.js 应用程序,它将显示推文。不幸的是,有一个错误说,"Cannot read property 'profileImageUrl' of Undefined." 这是这一行:

<img src={@props.details.tweet.user.profileImageUrl} />

我正在使用 React 0.13.3 来执行此操作。这是我的一段 Coffeescript CJSX 代码,其中包含有问题的 属性

Tweet = React.createClass
  propTypes:
    details: React.PropTypes.object.isRequired

  render: ->
    <article className="tweet-container">
        <div className="tweet-profile-picture">
            <img src={@props.details.tweet.user.profileImageUrl} />
        </div>
        <div className="tweet-body">
            <header className="tweet-header">
                <div className="tweet-metadata">
                    <a href="//twitter.com/#  {@props.details.tweet.user.screenName}">
                    <span className="name">{@props.details.tweet.user.name}</span>
                    <span className="screenName">{@props.details.tweet.user.screenName}</span>
                </a>
            </div>
        </header>
        <p>{@props.details.tweet.text}</p>
    </div>
    <div className="timestamp">
        <a href="//twitter.com/#{@props.details.tweet.user.screenName}/status/#{@props.details.tweet.idStr}">
            <time datetime={@props.details.tweet.createdAt}><moment(@props.details.createdAtTimestamp).fromNow()}</time>
        </a>
    </div>
</article>

为什么说头像 url 未定义?从哪里开始解决这个问题的最佳地点是哪里?预先感谢您的帮助。

检查包装此组件的推文的父组件

在你的 parentComponent 中会有 <Tweet details={details}/>

我最终修复了服务。结果 @props.details.tweet.user 在 api 中为空。代码现在可以正常工作了。