Skip to content

Instantly share code, notes, and snippets.

@kouphax
Created October 16, 2010 14:30
Show Gist options
  • Save kouphax/629836 to your computer and use it in GitHub Desktop.
Save kouphax/629836 to your computer and use it in GitHub Desktop.
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