Created
March 29, 2015 04:32
-
-
Save excid3/57a4e6e417d0682af7f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@TodoList = React.createClass | |
render: -> | |
`<ul> | |
{this.props.todos.map( | |
function(todo, index){ | |
return (<TodoItem key={index} id={todo.id} description={todo.description} completed_at={todo.completed_at} />) | |
}, this) | |
} | |
</ul>` | |
@TodoItem = React.createClass | |
getInitialState: -> | |
{completed: this.props.completed_at?} | |
handleChange: -> | |
$.ajax( | |
method: "PATCH" | |
url: "/todos/#{this.props.id}/complete" | |
success: => | |
this.setState completed: !this.state.completed | |
) | |
render: -> | |
`<li> | |
<label> | |
<input type="checkbox" checked={this.state.completed} onChange={this.handleChange} />{this.props.description} | |
</label> | |
</li>` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment