jQuery.Model.List.Cookie  class     

inherits: jQuery.Model.List
plugin: jquery/model/list/cookie
test: qunit.html

Provides a store-able list of model instances. The following retrieves and saves a list of contacts:

var contacts = new Contact.List([]).retrieve("contacts");

// add each contact to the page
contacts.each(function(){
addContact(this);
});

// when a new cookie is crated
$("#contact").submit(function(ev){
    ev.preventDefault();
    var data = $(this).formParams();

    // gives it a random id
    data.id = +new Date();
    var contact = new Contact(data);

    //add it to the list of contacts 
    contacts.push(contact);

    //store the current list
    contacts.store("contacts");

    //show the contact
    addContact(contact);
})

You can see this in action in the following demo. Create a contact, then refresh the page.

© Jupiter IT - JavaScriptMVC Training and Support