Skip to content

Instantly share code, notes, and snippets.

@ykhs
Created October 22, 2014 03:06
Show Gist options
  • Save ykhs/f2ab66e8a67be16781d3 to your computer and use it in GitHub Desktop.
Save ykhs/f2ab66e8a67be16781d3 to your computer and use it in GitHub Desktop.
JavaScript養成読本 特集1 第7章 リスト1 訂正
App.NoteListItemView = Backbone.View.extend({
tagName: 'tr',
initialize: function() {
// モデルのdestroyイベントを監視して
// Backbone.Viewのremove()メソッドを呼び出す
this.listenTo(this.model, 'destroy', this.remove);
},
// [Delete]ボタンを監視して
// onClickDelete()メソッドを呼び出す
events: {
'click .js-delete': 'onClickDelete'
},
render: function() {
var template = $('#noteListItemView-template').html();
var compiled = _.template(template);
var html = compiled(this.model.toJSON());
this.$el.html(html);
return this;
},
onClickDelete: function() {
// モデルを削除する
this.model.destroy();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment