In my backbone function i made a name space for me as var taskListPhraseI = {}; in using this name space all my function are assigned.
while i fetching the collection from collection class, using the each function i am passing to renderBoard, in the each will not aware about the this key word on this point, i used a variable declared as that and assigned to this, using that i am calling the function, but the render function throw the error as
TypeError: that.renderBoard is not a function
[Break On This Error]
that.renderBoard(item)
but i do have the renderBoard function. any give me a clue to solve this?
my part of code :
taskListPhraseI.allView = Backbone.View.extend({
el:$('.boardHolder'),
initialize:function(){
this.collection = new taskListPhraseI.collection();
this.collection.fetch({success:this.render});
},
render:function(data){
var that = this;
_.each(data.models, function(item){
that.renderBoard(item) // throw the error..
},this);
},
renderBoard:function(item){
console.log('item'); // i am not getting the call here...
}
});
Try to replace
this.collection.fetch({success:this.render});withthis.collection.fetch({success:_.bind(this.render, this)});.You are passing function
this.renderwithout its context, which can be fixed bybindin underscore library.