简体   繁体   English

在Rails上反应:Jsx和Coffeescritpt显示@props

[英]React on Rails: Jsx and Coffeescritpt display @props

I am very new to React. 我对React非常陌生。

How do I display @props using Jsx and CoffeeScript ? 如何使用JsxCoffeeScript显示@props

In my file records.js.jsx.coffee I have the following code to display a record's date and title: 在我的文件records.js.jsx.coffee我具有以下代码来显示记录的日期和标题:

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

The error I am receiving is SyntaxError: unknown: Unexpected token (5:11) 我收到的错误是SyntaxError: unknown: Unexpected token (5:11)

I was hoping I could escape the code using the back ticks ` 我希望我可以使用反斜杠转义代码`

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

Using this instead of the @ symbol worked. 使用this而不是@符号起作用。

From what I have read the @ symbol compiles to window not this as I would have expected using CoffeeScript 从我已阅读了@符号编译为window没有this ,我会使用CoffeeScript的预期

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM