我的应用程序在Meteor React.js tutorial中崩溃(下面)。我似乎无法找到问题,代码完全来自教程。救命啊!
Desktop/simple-todos-react/.meteor/local/build/programs/server/app/simple-todos-react.js:14
React.render(<App />, document.getElementById("render-target")); // 6
^
SyntaxError: Unexpected token <
at Desktop/simple-todos-react/.meteor/local/build/programs/server/boot.js:241:30
at Array.forEach (native)
at Function._.each._.forEach (/.meteor/packages/meteor-tool/.1.1.9.1u3q681++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
at /Desktop/simple-todos-react/.meteor/local/build/programs/server/boot.js:137:5
Exited with code: 8
Your application is crashing. Waiting for file change.
简单待办事项-react.html
<head>
<title>Todo List</title>
</head>
<body>
<div id="render-target"></div>
</body>
简单待办事项-react.js
if (Meteor.isClient) {
// This code is executed on the client only
Meteor.startup(function () {
// Use Meteor.startup to render the component after the page is ready
React.render(<App />, document.getElementById("render-target"));
});
}
App.jsx
// App component - represents the whole app
App = React.createClass({
getTasks() {
return [
{ _id: 1, text: "This is task 1" },
{ _id: 2, text: "This is task 2" },
{ _id: 3, text: "This is task 3" },
{ _id: 4, text: "This is task 4" },
{ _id: 5, text: "This is task 5" }
];
},
renderTasks() {
return this.getTasks().map((task) => {
return <Task key={task._id} task={task} />;
});
},
render() {
return (
<div className="container">
<header>
<h1>Todo List</h1>
</header>
<ul>
{this.renderTasks()}
</ul>
</div>
);
}
});
Task.jsx
// Task component - represents a single todo item
Task = React.createClass({
propTypes: {
// This component gets the task to display through a React prop.
// We can use propTypes to indicate it is required
task: React.PropTypes.object.isRequired
},
render() {
return (
<li>{this.props.task.text}</li>
);
}
});
答案 0 :(得分:6)