hydrate: function (data) {
// TODO - DRY it
// expect data is in the form of { locations: [array of codes], isApplied: boolean}
var invalid = _.isUndefined(data) || _.isUndefined(data.locations) || _.isUndefined(data.isApplied),
valid = !invalid && _.isArray(data.locations) && _.isBoolean(data.isApplied);
if (valid) {
this.locations.reset();
this.locations.fetchByCodes(data.locations);
this.setFilter(data.isApplied);
}
},
Cause of the issue, because the validation happens when setFilter is called but ajax call to fetchByCodes hadn't completed yet.
Look into using promise object for this? or pass in a callback?
https://github.com/illyfrancis/bogo/blob/master/bogosuh.v5/js/models/SettlementLocationCriterion.js#L35
Cause of the issue, because the validation happens when setFilter is called but ajax call to fetchByCodes hadn't completed yet.
Look into using promise object for this? or pass in a callback?
Refer to this for more info on promise - http://stackoverflow.com/questions/6080050/how-does-jquerys-promise-method-really-work