App.jsx 962 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // App component : represents the whole app.
  2. App = React.createClass({
  3. // This mixin makes the getMeteorData work.
  4. mixins: [ReactMeteorData],
  5. // Loads items from the Tasks collection and puts them on this.data.tasks.
  6. getMeteorData() {
  7. let result = {
  8. tasks: Tasks.find({}).fetch()
  9. };
  10. // Meteor._debug("result", result);
  11. return result;
  12. },
  13. renderTasks() {
  14. return this.data.tasks.map((task) => {
  15. // Meteor._debug(task._id);
  16. return <Task key={task._id} task={task} />;
  17. });
  18. },
  19. render() {
  20. return (
  21. <div className="container">
  22. <header>
  23. <h1>Todo list</h1>
  24. {/* These are JSX comments. */}
  25. <form className="new-task" onsubmit={this.handleSubmit} >
  26. <input type="text" ref="textInput" placeholder="Type to add new tasks" />
  27. </form>
  28. </header>
  29. <ul>
  30. {this.renderTasks()}
  31. </ul>
  32. </div>
  33. );
  34. }
  35. });