Good evening, I'm getting via JSON a List
with the structure below:
anexo: [{cod: 5, nome: "anexo1.pdf"}, {cod: 6, nome: "texto.txt"}]
And I use the function below:
$.getJSON(url + cod,
function (ajax) {
for (var i = 0; i < ajax.anexo.length; i++) {
//alert(ajax.anexo[i].nome);
$.each(ajax.anexo[i], function (k, value) {
$("#formAnexo").find($('[name="anexo.' + k + '"]')).each(function () {
setElementValue(this, value, 'anexo.' + k);
});
});
}
});
This function gets the data from JSON and fills the <textarea>
of my form.
In case of only 1 item, it is working. Now if there are 2 or more items, like the structure I presented at the beginning, only one data is appearing in the form (the latter overwrites the previous ones - so I understood).
My form looks like this:
<label>Anexo:</label>
<textarea rows="5" id="nome" readonly="nome" name="anexo.nome" ></textarea>
How can I fix this so that my JSON has a% w of% of 2 or more items, and that these are added to this% w / o%?