原谅我到处搜索,我是reactjs的新手,并尝试了一些示例。我有一个错误
Uncaught ReferenceError: mountNode is not defined
我从这里跟随示例http://facebook.github.io/react/tips/initial- ajax.html
我的代码看起来像这样
<!DOCTYPE html> <html> <head> <title><%= title %></title> <link rel='stylesheet' href='/stylesheets/style.css' /> <script src="//code.jquery.com/jquery-1.11.0.min.js"></script> <script src="/javascripts/reactjs/react.js"></script> <script src="/javascripts/reactjs/JSXTransformer.js"></script> </head> <body> <h1><%= title %></h1> <p>Welcome to <%= title %></p> <div id="example"></div> <script src="/javascripts/reactjs/build/helloworld.js"></script> <script type="text/jsx"> /** @jsx React.DOM */ var UserGist = React.createClass({ getInitialState: function() { return { username: '', lastGistUrl: '' }; }, componentDidMount: function() { $.get(this.props.source, function(result) { var lastGist = result[0]; this.setState({ username: lastGist.owner.login, lastGistUrl: lastGist.html_url }); }.bind(this)); }, render: function() { return ( <div> {this.state.username}last gist is <a href={this.state.lastGistUrl}>here</a>. </div> ); } }); React.renderComponent( <UserGist source="https://api.github.com/users/octocat/gists" />, mountNode ); </script> </body> </html>
先感谢您!
您需要告诉React在哪里安装<UserGist />组件。您可能需要替换mountNode为document.getElementById('example')以引用您的<div id="example"></div>元素:
<UserGist />
mountNode
document.getElementById('example')
<div id="example"></div>
React.render( <UserGist source="https://api.github.com/users/octocat/gists" />, document.getElementById('example') );