1
Good evening, I’m receiving 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 fetches the JSON data and fills the <textarea> of my form.
In the case of only one 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 last one overwrites the previous ones - from what I understood).
My form is 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 List of 2 or more items, and these shall be added to textarea?
Your form has a single
textareaor several (in other words, it’s for the name of each item to end up in a different textarea, or for all of them to go to the same textarea, separated by spaces or line breaks for example)? Is there an element with the nameanexo.cod? And whatsetElementValueago?– mgibsonbr