沿着 Facebook 的read.js 教程,我得到这个错误:
Uncaught TypeError: Property 'CommentList' of object [object Object] is not a function
实际上 react.js 自己的示例页面有:
Uncaught TypeError: object is not a function
谁能解释正确的用法?
我在教程中的进步
导入以下两个 javascript:
http://fb.me/react-0.4.1.js
http://fb.me/JSXTransformer-0.4.1.js
HTML 是一行:
<div id="content"></div>
而 javascript 或者更确切地说<script type="text/jsx">
看起来像这样:
var CommentBox = React.createClass({
render: function() {
return (
<div class="commentBox">
<h1>Comments</h1>
<CommentList />
<CommentForm />
</div>
);
}
});
React.renderComponent(
<CommentBox />,
document.getElementById('content')
);
var CommentList = React.createClass({
render: function() {
return (
<div class="commentList">
<Comment author="Pete Hunt">This is one comment</Comment>
<Comment author="Jordan Walke">This is *another* comment</Comment>
</div>
);
}
});