I am trying to build a form based off of column names I get from a PHP script, through AJAX, and a pre-defined array of column details. I am hoping to assign these pre-defined attributes to the incoming columns and build a form. For example, if I ever get the column "UserName" I want to to always be an < input >
The template
var template = {
UserName : {
label: "User Name:",
type: "input"
}
UserId : {
label: "User Id:",
type: "text"
}
}
Incoming JSON array from AJAX request
{"UserName":"bob", "UserId":"1"}
Now I need to somehow 'match' these. I myself am not sure exactly what to do here.
$.each(data, function(i,e){
// if index (such as UserName) is found in template array, maybe add the attributes to it?
});