데이터베이스를 업데이트 한 다음 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이 업데이트되지 않아서 콜백이 실행되지 않습니다. 내가 도대체 뭘 잘못하고있는 겁니까? 튜토리얼을 따라 갔지만 튜토리얼에서는 모든 것이 잘 작동한다.
내가 대신 update''의'create'을 시도 :
* 정말 아마도 당신이 뭘 하려는지 이해하지만,하지 않는 UPDATE *
이 시도 여전히 운이 없다. – sehummel
table.toJSON(); - 코드 라인은 아무것도하지 않습니다. 반환하는 JSON으로 뭔가를해야합니다. – asgeo1