In my backbone.js view i have a function that has the code below. I would usually call this function using this.addLayerToList()
, but since it's in the $.each
this. is not what I want. Can anyone help here? How would I call my function addLayerToList from the $.each
?
initLayerList: function(){
$.each(baseLayers, function() {
this.addLayerToList(this);
});
},
addLayerToList : function() {
//...some code here
}
This should work.
initLayerList: function(){
var that = this;
$.each(baseLayers, function(idx, layer) {
that.addLayerToList(layer);
});
},
addLayerToList : function() {
//...some code here
}