Skip to content

Instantly share code, notes, and snippets.

@nathanpalmer
Created August 1, 2011 14:00
Show Gist options
  • Save nathanpalmer/1118173 to your computer and use it in GitHub Desktop.
Save nathanpalmer/1118173 to your computer and use it in GitHub Desktop.
var ItemCollection = Spine.Model.setup("Item", [ "itemToAdd", "allItems", "selectedItems" ]);
ItemCollection.extend(DataBind);
ItemCollection.include({
addItem: function() {
if (this.itemToAdd != "") {
this.allItems.push(this.itemToAdd);
this.itemToAdd = "";
this.save();
}
},
removeSelected: function() {
var allItems = this.allItems;
this.selectedItems.forEach(function(item) {
var index = allItems.indexOf(item);
if (index >= 0) {
allItems.splice(index,1);
}
});
this.selectedItems = [];
this.save();
},
sort: function() {
this.allItems.sort();
this.save();
}
});
var Item = ItemCollection.create({ itemToAdd: "", allItems: [ "Fries", "Eggs Benedict", "Ham" ], selectedItems: [] });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment