Created
January 17, 2015 15:26
-
-
Save Jeiwan/6776368f2f02fe474b18 to your computer and use it in GitHub Desktop.
// source http://jsbin.com/yiqivo
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>JS Bin</title> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.7.0/underscore-min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.1.2/backbone-min.js"></script> | |
| </head> | |
| <body> | |
| <script id="jsbin-javascript"> | |
| var Item = Backbone.Model.extend({ | |
| defaults: { | |
| title: '' | |
| } | |
| }); | |
| var List = Backbone.Collection.extend({ | |
| model: Item | |
| }); | |
| var ListView = Backbone.View.extend({ | |
| el: $('body'), | |
| events: { | |
| 'click button#add': 'addItem' | |
| }, | |
| initialize: function() { | |
| this.collection = new List(); | |
| this.collection.bind('add', this.appendItem); | |
| this.render(); | |
| }, | |
| render: function() { | |
| $(this.el).append('<input id="item-input" type="text" /><button id="add">Add</button>'); | |
| $(this.el).append('<ul id="list"></ul>'); | |
| }, | |
| addItem: function() { | |
| var $input = $('#item-input'); | |
| if ($input.val().length > 0) { | |
| var item = new Item({title: $input.val()}); | |
| this.collection.add(item); | |
| $input.val(''); | |
| } else { | |
| alert('Item is empty!'); | |
| } | |
| }, | |
| appendItem: function(item) { | |
| $('#list').append('<li>' + item.get('title') + '</li>'); | |
| } | |
| }); | |
| var listView = new ListView(); | |
| </script> | |
| <script id="jsbin-source-javascript" type="text/javascript">var Item = Backbone.Model.extend({ | |
| defaults: { | |
| title: '' | |
| } | |
| }); | |
| var List = Backbone.Collection.extend({ | |
| model: Item | |
| }); | |
| var ListView = Backbone.View.extend({ | |
| el: $('body'), | |
| events: { | |
| 'click button#add': 'addItem' | |
| }, | |
| initialize: function() { | |
| this.collection = new List(); | |
| this.collection.bind('add', this.appendItem); | |
| this.render(); | |
| }, | |
| render: function() { | |
| $(this.el).append('<input id="item-input" type="text" /><button id="add">Add</button>'); | |
| $(this.el).append('<ul id="list"></ul>'); | |
| }, | |
| addItem: function() { | |
| var $input = $('#item-input'); | |
| if ($input.val().length > 0) { | |
| var item = new Item({title: $input.val()}); | |
| this.collection.add(item); | |
| $input.val(''); | |
| } else { | |
| alert('Item is empty!'); | |
| } | |
| }, | |
| appendItem: function(item) { | |
| $('#list').append('<li>' + item.get('title') + '</li>'); | |
| } | |
| }); | |
| var listView = new ListView();</script></body> | |
| </html> |
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 Item = Backbone.Model.extend({ | |
| defaults: { | |
| title: '' | |
| } | |
| }); | |
| var List = Backbone.Collection.extend({ | |
| model: Item | |
| }); | |
| var ListView = Backbone.View.extend({ | |
| el: $('body'), | |
| events: { | |
| 'click button#add': 'addItem' | |
| }, | |
| initialize: function() { | |
| this.collection = new List(); | |
| this.collection.bind('add', this.appendItem); | |
| this.render(); | |
| }, | |
| render: function() { | |
| $(this.el).append('<input id="item-input" type="text" /><button id="add">Add</button>'); | |
| $(this.el).append('<ul id="list"></ul>'); | |
| }, | |
| addItem: function() { | |
| var $input = $('#item-input'); | |
| if ($input.val().length > 0) { | |
| var item = new Item({title: $input.val()}); | |
| this.collection.add(item); | |
| $input.val(''); | |
| } else { | |
| alert('Item is empty!'); | |
| } | |
| }, | |
| appendItem: function(item) { | |
| $('#list').append('<li>' + item.get('title') + '</li>'); | |
| } | |
| }); | |
| var listView = new ListView(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment