[英]Facebook React.js Example error?
I am tryin out Facebook's Reactjs library and found it awesome. 我正在试用Facebook的Reactjs库并发现它很棒。 I have ran through the exampe/tutorial and got it working.
我已经完成了示例/教程并使其正常运行。
Now i am at : http://facebook.github.io/react/docs/interactivity-and-dynamic-uis.html 现在我在: http : //facebook.github.io/react/docs/interactivity-and-dynamic-uis.html
And I am trying out the code: 我正在尝试代码:
/** @jsx React.DOM */
var LikeButton = React.createClass({
getInitialState: function() {
return {liked: false};
},
handleClick: function(event) {
this.setState({liked: !this.state.liked});
},
render: function() {
var text = this.state.liked ? 'like' : 'unlike';
return (
<p onClick={this.handleClick}>
You {text} this. Click to toggle.
</p>
);
}
});
React.renderComponent(
<LikeButton />,
document.getElementById('example')
);
After running the code above, i get nothing. 运行上面的代码后,我什么都没得到。 In my google chrome console, the error i got was
Uncaught SyntaxError: Unexpected token <
, on the line starting with <p onClick={this.handleClick}>
在我的谷歌Chrome控制台中,我得到的错误是
Uncaught SyntaxError: Unexpected token <
,在以<p onClick={this.handleClick}>
开头的行上
I was wondering if there's anyone who can enlighten me as to what is wrong with the code ? 我想知道是否有人可以告诉我代码有什么问题?
Best Regards. 最好的祝福。
Ok, i know what the mistake was. 好的,我知道错误是什么。
Since i place the code in my question as an external file ( Like.js ), make sure that the script tag should read as follows: 由于我将代码放在我的问题中作为外部文件(Like.js),请确保脚本标记应如下所示:
<script type="text/jsx" src="Like.js"></script>
The "text/jsx" is required! “text / jsx”是必需的!
Thanks! 谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.