I've received a JSON object from my server and I want it to loop through all the returned values and populate two input text fields, which are created dynamically.
At the moment I have 2 records returned but it only populates one set of fields and the other set although created remains unpopulated. The console.log output shows there are two records:
0 Object {emailAdd: "[email protected]", emailDesc: "work"}
1 Object {emailAdd: "[email protected]", emailDesc: "home"}
This is the Jquery:
var emails = {% raw json_encode(emails) %};
$.each(emails, function(k,v) {
x = 1;
z = x++;
$('<input type="email" placeholder="Email" value="" id="email'+x+'" data-name="emailAdd" /><input type="text" placeholder="Description" value="" id="email'+z+'" data-name="emailDesc"/>').appendTo('#email');
$('#email' + x + '').val(v.emailAdd);
$('#email' + z + '').val(v.emailDesc);
x++;
console.log(k, v);
});
It seems to be just returning the last record, instead of all records. How can I show all the returned records?