Part3
CRUD!
1. Todo item list CRUD
1.1. C-reate
1.2. U-pdate
// renders individual todo items list (li) app.TodoView = Backbone.View.extend({ tagName: 'li', template: _.template($('#item-template').html()), render: function(){ this.$el.html(this.template(this.model.toJSON())); this.input = this.$('.edit'); return this; // enable chained calls }, initialize: function(){ this.model.on('change', this.render, this); }, events: { 'dblclick label' : 'edit', 'keypress .edit' : 'updateOnEnter', 'blur .edit' : 'close' }, edit: function(){ this.$el.addClass('editing'); this.input.focus(); }, close: function(){ var value = this.input.val().trim(); if(value) { this.model.save({title: value}); } this.$el.removeClass('editing'); }, updateOnEnter: function(e){ if(e.which == 13){ this.close(); } } });let view = new app.TodoView(model);
events: { 'dblclick label' : 'edit', 'keypress .edit' : 'updateOnEnter', 'blur .edit' : 'close' },
edit: function(){ this.$el.addClass('editing'); this.input.focus(); },
1.3. D-elete
Last updated