Created
April 8, 2011 18:59
-
-
Save adomado/910498 to your computer and use it in GitHub Desktop.
Revisions
-
adomado created this gist
Apr 8, 2011 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,60 @@ $(function() { // Model window.FeedItemModel = Backbone.Model.extend({ initialize : function(id, graph) { this.id = id; this.graph = graph; }, like : function() { // Like this feedItem }, comment : function(message) { // comment on this feed item } }); // Collection window.FeedListCollection = Backbone.Collection.extend({ model : FeedItemModel, localStorage : new Store("feed"), items : function() { // returns all feedItems } }); window.FeedItems = new FeedListCollection; // View window.FeedListView = Backbone.View.extend({ tagName : "li", className : "feed-item", initialize : function(feedItemsCollection) { feedItemsCollection.bind("add", this.render); }, render : function(feedItem) { $("#feed-items").append("<li>" + feedItem.get("graph") + "</li>"); return this; } }); window.App = new FeedListView(FeedItems); FeedItems.add(new FeedItemModel({graph : "abc"})); FeedItems.add(new FeedItemModel({graph : "def"})); FeedItems.add(new FeedItemModel({graph : "ghi"})); FeedItems.create({graph : "foo"}); });