Skip to content

Instantly share code, notes, and snippets.

@theresaanna
Last active August 29, 2015 14:12
Show Gist options
  • Save theresaanna/dc9c816ab1bf967a6758 to your computer and use it in GitHub Desktop.
Save theresaanna/dc9c816ab1bf967a6758 to your computer and use it in GitHub Desktop.
var loadSingleEntity = function(e) {
var urls = [];
urls.push(callAPI(buildURL(e)));
urls.push(callAPI(url for committee info));
$.when.apply($, urls).done(function() {
var i,
len = arguments.length;
e.results = {};
for (i = 0; i < len; i++) {
if (i === 0){
e.results = arguments[i][0].results;
}
else {
// committee data
e.results[entitiesArray[i]] = arguments[i][0].results;
}
}
events.emit('render:singleEntity', e);
}).fail(function() {
events.emit('err:load:singleEntity');
});
});
}
buildCandidateContext: function(results) {
// usual stuff...
for (i = 0; i < len; i++) {
newCandidateObj = {
id: '',
name: '',
office: '',
election: '',
party: '',
state: '',
district: '',
incumbent_challenge: '',
nameURL: '',
committee_name: ''
};
// more usual stuff...
if (results[i] has a property that indicates there is associated committee data) {
newCandidateObj.committee_name = whatever;
}
candidates.push(newCandidateObj);
}
return candidates;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment