次のバックボーン ビューがあります。
Chatbox.Views.Message = Backbone.View.extend({
template: _.template($("#tmplt-Message").html()),
events: {
"click a.remove_link" : "clear"
},
initialize: function () {
_.bindAll(this, 'render', 'remove');
this.model.on('clear', this.clear);
this.listenTo(this.model, 'destroy', this.remove);
},
render: function () {
return $(this.el).append(this.template(this.model.toJSON())) ;
},
clear: function() {
this.model.destroy();
}
});
クラスのリンクをクリックするとremove_link
、clear()
関数が適切に呼び出されてdestroy()
実行されます。
外部からを呼び出すにはどうすればよいですかclear()
。私の場合、コレクションがあり、このコレクション内のモデルを削除したいのです。現在、私はこれをやろうとしています:
message = Chatbox.ChatLogCollection.where({ hash: hash});
message.clear();
Chatbox.ChatLogCollection.remove(message);
しかし、私は得る: TypeError: message.clear は関数ではありません
clear()
ビューからモデルを削除するにはどうすればよいですか?