mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-08 03:00:26 -04:00
Ensuring the Todo model has a sane default
This commit is contained in:
@@ -5,7 +5,12 @@ $(function(){
|
||||
|
||||
// Our basic **Todo** model. Has `content`, `order`, and `done` attributes.
|
||||
window.Todo = Backbone.Model.extend({
|
||||
|
||||
|
||||
// Ensure each todo is created with the content field filled in.
|
||||
initialize : function(){
|
||||
if(!this.get("content")) this.set({"content": "New Todo"}, {silent:true})
|
||||
},
|
||||
|
||||
// Toggle the `done` state of this todo item.
|
||||
toggle: function() {
|
||||
this.save({done: !this.get("done")});
|
||||
|
||||
Reference in New Issue
Block a user