123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- App = React.createClass({
-
- mixins: [ReactMeteorData],
-
- getMeteorData() {
- let result = {
- tasks: Tasks.find({}, {sort: {createdAt: -1}}).fetch()
- };
-
- return result;
- },
- renderTasks() {
- return this.data.tasks.map((task) => {
-
- return <Task key={task._id} task={task} />;
- });
- },
- handleSubmit(event) {
- event.preventDefault();
-
-
- var text = ReactDOM.findDOMNode(this.refs.textInput).value.trim();
- Tasks.insert({
- text: text,
- createdAt: new Date()
- });
-
- ReactDOM.findDOMNode(this.refs.textInput).value = '';
- },
- render() {
- return (
- <div className="container">
- <header>
- <h1>Todo list</h1>
- <label className="hide-completed">
- <input type="checkbox" readonly={true}
- checked={this.state.hideCompleted}
- onClick={this.toggleHideCompleted} />
- Hide completed
- </label>
- {/* These are JSX comments. */}
- {/* Beware: for React, onsubmit is not the same as onSubmit, the former doesn't work */}
- <form className="new-task" onSubmit={this.handleSubmit} >
- <input type="text" ref="textInput" placeholder="Type to add new tasks" />
- </form>
- </header>
- <ul>
- {this.renderTasks()}
- </ul>
- </div>
- );
- }
- });
|