鍍金池/ 問答/HTML/ React官方文檔里React理念的demo代碼問題

React官方文檔里React理念的demo代碼問題

1.出現(xiàn)問題,不知道哪里錯(cuò)了?

Uncaught SyntaxError: Inline Babel script: Unexpected token, expected , (68:33)
  66 |                                 <td colSpan="2"><ProductCategoryRow category={item[0].category} /></td>
  67 |                                 </tr>   
> 68 |                                  {item.map((line) => {
     |                                  ^
  69 |                                             return  (<ProductRow name={line.name} price={line.price} key={line.name}/>)}
  70 |                                         )}
  71 |                                         
    at Parser.pp$5.raise (babel.js:17994)
    at Parser.pp.unexpected (babel.js:15337)
    at Parser.pp.expect (babel.js:15325)
    at Parser.pp$3.parseParenAndDistinguishExpression (babel.js:17368)
    at Parser.pp$3.parseExprAtom (babel.js:17263)
    at Parser.parseExprAtom (babel.js:20637)
    at Parser.pp$3.parseExprSubscripts (babel.js:17048)
    at Parser.pp$3.parseMaybeUnary (babel.js:17028)
    at Parser.pp$3.parseExprOps (babel.js:16958)
    at Parser.pp$3.parseMaybeConditional (babel.js:16935)


2.出錯(cuò)局部的代碼:

class ProductTable extends React.Component {
            constructor(props) {
                super(props);
            }

            render() {
                return (
                    <table>
                    <thead>
                        <tr>
                            <th><span className="title">Name</span></th>
                            <th><span className="title">Price</span></th>
                        </tr>
                        </thead>
                        <tbody>
                            {this.props.categoryArray.map((item,index) => {
                            return (
                                <tr key={index}>
                                <td colSpan="2"><ProductCategoryRow category={item[0].category} /></td>
                                </tr>   
                                 {item.map((line) => {
                                            return  (<ProductRow name={line.name} price={line.price} key={line.name}/>)}
                                        )}
                                        
                            )})}
                            
                            </tbody>
                    </table>
                )
            }
        }

3.文檔鏈接https://doc.react-china.org/d...

回答
編輯回答
卟乖

babel了沒有?
/加一個(gè)文件.bablerc

{
  "presets": [
    "es2015",
    "stage-0",
    "react"
  ]
}
2018年4月18日 10:31