0
I have a table dynamically created and within it a select in which I use a map to create your options.
json.map(item => {
var corpo = '';
corpo += '<td>';
corpo += ' <select>';
arrStatus.map(item => {
corpo += ' <option value="' + item.freteStatusID + '">' + item.status + '</option>';
})
corpo += ' </select>';
corpo += '</td>'
//adiciona esta linha na tabela
$('#tabela').append(corpo);
$('option[value=' + item.freteStatusID + ']').attr('selected', 'selected');
}
When I try to use the .attr within the map I receive this result with two options being selected
<select>
<option value="5">Aceito pelo embarcador</option>
<option value="2">Agendado</option>
<option value="3">Declinado</option>
<option value="1" selected="selected">Recebido</option>
<option value="6" selected="selected">Rejeitado pelo embarcador</option>
<option value="4">Removido</option>
</select>
<select>
<option value="5">Aceito pelo embarcador</option>
<option value="2">Agendado</option>
<option value="3">Declinado</option>
<option value="1" selected="selected">Recebido</option>
<option value="6" selected="selected">Rejeitado pelo embarcador</option>
<option value="4">Removido</option>
</select>
How can I make only one option by select take the "Selected attribute"?