Last active
October 23, 2018 02:29
-
-
Save jsdecena/f8d3fea1a592c77dc45221a9b9f7e26a to your computer and use it in GitHub Desktop.
QNA JSON
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Questions array: | |
const questions = [ | |
{ | |
"form_criteria_id":"46", | |
"field_name":"pumpstation_general", | |
"field_label":"General repairs required?", | |
"mandatory":false, | |
"action":"dropdown", | |
"input_type":[ | |
{ | |
"id":7, | |
"text":"Yes", | |
"value":"yes", | |
"created_at":"2018-10-21 22:36:18", | |
"updated_at":"2018-10-21 22:36:18" | |
}, | |
{ | |
"id":8, | |
"text":"No", | |
"value":"no", | |
"created_at":"2018-10-21 22:36:18", | |
"updated_at":"2018-10-21 22:36:18" | |
} | |
], | |
"value":"" | |
}, | |
{ | |
"form_criteria_id":"60", | |
"field_name":"pumpstation_control_panel_photo", | |
"field_label":"Control panel photos", | |
"mandatory":false, | |
"action":"upload", | |
"input_type":[ | |
], | |
"value":"" | |
} | |
] | |
// Answers array: | |
const answers = [ | |
{ | |
"id":"1", | |
"form_id":1, | |
"form_criteria_id":46, | |
"form_criteria_option_id":7, | |
"value":"yes", | |
"text":"Yes" | |
} | |
] | |
// Merge into | |
[ | |
{ | |
"form_criteria_id":"46", | |
"field_name":"pumpstation_general", | |
"field_label":"General repairs required?", | |
"mandatory":false, | |
"action":"dropdown", | |
"input_type":[ | |
{ | |
"id":7, | |
"text":"Yes", | |
"value":"yes", | |
"created_at":"2018-10-21 22:36:18", | |
"updated_at":"2018-10-21 22:36:18" | |
}, | |
{ | |
"id":8, | |
"text":"No", | |
"value":"no", | |
"created_at":"2018-10-21 22:36:18", | |
"updated_at":"2018-10-21 22:36:18" | |
} | |
], | |
"value":"yes" /** Set the answer here for criteria id of 46 **/ | |
}, | |
{ | |
"form_criteria_id":"60", | |
"field_name":"pumpstation_control_panel_photo", | |
"field_label":"Control panel photos", | |
"mandatory":false, | |
"action":"upload", | |
"input_type":[ | |
], | |
"value":"" | |
} | |
] | |
// Solution? | |
questions.forEach(q => { | |
answers.forEach(a => { | |
if (a.form_criteria_id == q.form_criteria_id) { | |
return q.value = a.value; | |
} | |
}); | |
}); | |
// Alternate?? | |
questions.map(q => { | |
answers.filter(a => { | |
return q.form_criteria_id == a.form_criteria_id ? q.value = a.value : ''; | |
}); | |
}); | |
console.log(questions); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment