データベースを更新してからDOMを更新できるように、アプリに機能を追加しようとしています。データベースは正常に更新されますが、DOM は更新されません。ここに私の見解の一部があります:
App.Views.Table = Backbone.View.extend({
tagName: 'span',
initialize: function(options) {
this.model.on('change', this.render, this);
this.model.on('update', this.remove, this);
this.template = this.options.template;
this.url = this.options.url;
},
events: {
'click .verify': 'verify',
'click .spam': 'spam',
'click .duplicate': 'duplicate'
},
verify: function(e) {
id = e.currentTarget.id;
table = new App.Models.Table({ id: id });
table.urlRoot = this.url;
table.fetch();
table.toJSON();
table.set('verified', 1);
table.save();
},
spam: function(e) {
...
},
duplicate: function(e) {
...
},
remove: function() {
this.$el.remove();
console.log('hello');
},
retrieveTemplate: function(model) {
return _.template($('#' + this.template).html(), model);
},
render: function() {
//console.log(this);
this.$el.html(this.retrieveTemplate(this.model.toJSON()));
return this;
}
});
私が理解しているように、完了しthis.model.on('update', this.remove, this);
たら削除機能を呼び出す必要がありますsave
。console.log
しかし、 を取得しておらず、DOM が更新されていないため、コールバックは起動していません。私は何を間違っていますか?チュートリアルに従いましたが、チュートリアルではすべて正常に動作します。