Here is a nodejs code that copies values from one object (submitted from a firm) to a model object.
Model:
var directory_model = {
"link_title": {
"value": 1, // This needs to be filled with object data
"validation": null
},
"link_desc": {
"value": 2, // This needs to be filled with object data
"validation": null
},
};
Object values that must get into the model:
{ link_title: 'test1', link_desc: 'test2' }
Here is the code that does, it with lodash. This code does the job:
_.forOwn(directory_model, function(directory_model_value, directory_model_key) {
_.forOwn(fields, function(fields_value, fields_key) {
"use strict";
if (directory_model_key === fields_key) {
directory_model[directory_model_key].value = fields_value;
}
});
});
I don't like the nested loop, and would like to know if you know another way to do this. I found several ways, but none of them works, because of the nested properties.