I'm trying to build several dynamic if statements based on the definition in the argument of the function. I should be able to run them if the particular keys and vales are provided. I can read all the keys and values, but not sure how to build a code upon them. This is the object passed as a function argument:
param = {
'fields': {
'email' : {
'match' : 'email'
},
'countAdults': {
'match' : 'number',
'range' : '1, 10'
}
}
};
//And this bit is trying to parse the object
$.each(param.fields, function(key, value){ // reading definitions from the parameter
if(name == "'+key+'") $('[name="'+key+'"]').mandatory(); // define the begining of if
$.each(param.fields[key], function(subk, subv){
+= '.'+subk+'("'+subv+'")'; // adding more to the if statement
});
});
return (all if statement);
}
After returning all of these if statements I would also like to run an else statement for default cases. I'm trying to move these bits of code from the body of a main function, to a place where you call the function, so that I wouldn't have to customize the body of the function each time.