I've got this piece code in a view:
//dom events -----
,events:{
'click #language-switcher input[type="radio"]': function(e){
this.current_language = $(e.target).val();
}
,'click .create-gcontainer-button': function(){
this.collection.add(new Group());
}
}
,set_events:function(){
//model events -----
this.listenTo(this.collection,'add',function(group){
var group = new GroupView({ model: group });
this.group_views[group.cid] = group;
this.groups_container.append(group.el);
EventTools.trigger("group_view:create",{ lang:this.current_language });
});
this.listenTo(this.collection,'destroy',function(model){
console.log('removing model:', model);
});
//emitter events ---
EventTools.on('group_view:clear',this.refresh_groups, this);
}//set_events
Note: set_events gets called on initialization. Well, I don't like defining events in 2 different places, but since the docs say that events defined from the 'events' prop are bound to the element (or children of it if a selector is passed), I guess I cannot use it for other types of events. Am I correct?
I also tried to define 'events' from inside my set_events function, but for some reason that leads to a memory leak or something similar (browser gets stuck).
So another more general question could be: on a Backbone view, is there a way to define all the events in one single place?