Created
October 16, 2010 14:30
-
-
Save kouphax/629836 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var model = {}, // empty model object | |
list = $("#todo-list"), | |
form = $('#new-task-form'), | |
addBtn = $("#add"), | |
saveBtn = $("#save"); | |
// link ui to model | |
form.link(model); | |
// handle onclick | |
addBtn.click(function () { | |
// clone the data model | |
var item = $.extend({}, model) | |
// generate template | |
$.tmpl("<li>${task}</li>", item).appendTo(list); | |
}); | |
// handle save | |
saveBtn.click(function () { | |
// pull back the data | |
var todos = list.find("li").map(function () { | |
return $(this).tmplItem().data; | |
}).get(); | |
// save the object | |
$.post("/Home/Save", todos, function () { | |
alert("Todos Saved"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment