Skip to content

Instantly share code, notes, and snippets.

@noedlm
Created November 9, 2017 19:01
Show Gist options
  • Save noedlm/a18802fb8b17bdd62891b5be222b1fb3 to your computer and use it in GitHub Desktop.
Save noedlm/a18802fb8b17bdd62891b5be222b1fb3 to your computer and use it in GitHub Desktop.
Coldfusion: Perks of iterating through structures and arrays using .each()
json = getPayload();
courses = deserializeJson(json); //this returns an array of structs
maxCourseId = getMaxId();
courses.each(function(course, index)) {
importClass(course, maxCourseId + index);
}
function importClass(required struct course, required numeric index) {
queryObject = new query();
arguments.course.each(function(key, value) {
queryObject.addParam(name=key, value=value);
});
//build and execute insert/update query. Here is where we use arguments.index
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment