/js/coffee/helloworld3.js
JavaScript | 49 lines | 44 code | 4 blank | 1 comment | 0 complexity | cab19fc56f0c42fb526ee8d4a634fc6f MD5 | raw file
- // Generated by CoffeeScript 1.3.3
- (function() {
- window.Item = Backbone.Model.extend({
- defaults: {
- part1: "hello",
- part2: "world"
- }
- });
- window.List = Backbone.Collection.extend({
- model: Item
- });
- window.ListView = Backbone.View.extend({
- events: {
- "click button#add": "addItem"
- },
- initialize: function() {
- _.bindAll(this);
- this.collection = new List();
- this.collection.bind("add", this.appendItem);
- this.counter = 0;
- return this.render();
- },
- render: function() {
- var self;
- self = this;
- this.$el.html(_.template($("#template_helloworld2").html(), {}));
- this.collection.each(function(item) {
- return self.appendItem(item);
- }, this);
- return $(".backbone").html(this.$el);
- },
- addItem: function() {
- var item;
- this.counter++;
- item = new Item();
- item.set({
- part2: item.get("part2") + this.counter
- });
- return this.collection.add(item);
- },
- appendItem: function(item) {
- return $("ul", this.$el).append("<li>" + item.get("part1") + " " + item.get("part2") + "</li>");
- }
- });
- }).call(this);