Commit ea7ba1f8 by Martin Kotula

use the bind function to pass context

parent 29eb2c3d
......@@ -37,21 +37,20 @@ define([
}
HomeViewModel.prototype.refresh = function () {
var that = this;
this.isRefreshing(true);
this.queryHandler.handle().then(function(data) {
var sensorsGroupedByName = _.groupBy(data, "name")
_.each(sensorsGroupedByName, function(sensorReadings, key){
this.queryHandler.handle().then(_.bind(function(data) {
var sensorsGroupedByName = _.groupBy(data, "name");
_.each(sensorsGroupedByName, _.bind(function(sensorReadings, key){
var latestReading = _.orderBy(sensorReadings, "timestamp").pop();
if(that.sensorsDict[key]){
that.updateSensor(key, latestReading);
if(this.sensorsDict[key]){
this.updateSensor(key, latestReading);
} else {
that.addSensor(key, latestReading);
this.addSensor(key, latestReading);
}
})
that.isRefreshing(false);
})
}, this));
this.isRefreshing(false);
}, this));
}
return { viewModel: HomeViewModel, template: homeTemplate };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment