I seem to have an issue with the parameters I am trying to set from within the success callback function:
var CampModel = CampDataModel.extend({
initialize : function(){
this.fetchActiveAndPending();
console.log(this.get('active'));
},
//Counts active and pending campaigns for front page.
CountActiveAndPending : function(data){
var active = 0;
var pending = 0;
$.each(data.returnValue,function(index,val){
if (val.ApprovedOnSite){
active++;
}
else
pending++;
});
this.set('active',active);
this.set('pending',pending);
},
//fetches data from server using campModel.
fetchActiveAndPending : function(){
console.log('fetching!');
that = this;
this.fetch({
success:function(model,response){
that.CountActiveAndPending(response);
}
});
}
});
return CampModel;
});
the result of this.get('active') is always the default number. If I try and use this.get('active') from within the success callback function it gives the right result. Is it possible to set a var from within the callback func and call it from outside, let's say the initialize function?