【问题标题】:React on Rails: Jsx and Coffeescritpt display @propsReact on Rails:Jsx 和 Coffeescritpt 显示 @props
【发布时间】:2016-03-15 13:00:33
【问题描述】:

我对 React 很陌生。

如何使用JsxCoffeeScript 显示@props

在我的文件records.js.jsx.coffee 中,我有以下代码来显示记录的日期和标题:

@Record = React.createClass
  render: ->
    `<tr>
      <td>{@props.record.date}</td>
      <td>{@props.record.title}</td>
     </tr>`

我收到的错误是SyntaxError: unknown: Unexpected token (5:11)

我希望我可以使用反引号来转义代码 `

【问题讨论】:

    标签: javascript ruby-on-rails reactjs jsx react-rails


    【解决方案1】:
    @Record = React.createClass
      render: ->
        `<tr>
          <td>{this.props.record.date}</td>
          <td>{this.props.record.title}</td>
         </tr>`
    

    使用this 代替@ 符号有效。

    根据我的阅读,@ 符号编译为 window 而不是 this,正如我使用 CoffeeScript 所期望的那样

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-08
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      相关资源
      最近更新 更多