I am using RequireJS and Backbone and listening to a collection
's add
event using listenTo
. I cannot figure out how to reference this
as the instance of the view I am in, in this case GroupView
.
define([
'underscore',
'backbone',
'handlebars',
...
...
], function(_,Backbone,Handlebars,...){
...
...
var GroupsView = Backbone.View.extend({
el: "#current-item",
collection: Groups,
model: Group,
groupTemplate: Handlebars.compile(GroupTemplate),
events: {
"click #add-group" : "addGroupClicked",
},
initialize: function(){
this.listenTo(Groups,'add',this.addGroup,this);
},
addGroup: function(group){
//I want a reference to this instance of GroupsView here.
//if I use this... it references
//Uncaught TypeError: Object [object global] has no method 'groupTemplate'
console.log(this.groupTemplate);
//Uncaught TypeError: Object [object global] has no method 'redrawGroups'
--> console.log(this.redrawGroups);
},
redrawGroups: function(){
},
...
...