I need to loop through a select
element on a HTML
page by putting the option
elements inside it. The problem is that in the attribute value
of these option
should receive the identifiers coming from the database, but it is appearing other numbers different from the value of the records and when the form is sent there is a persistence error no Java
because the identifier does not exist to make the foreign key relationship.
HTML :
<div class="input-group">
<select name="objeto.oid" id="objetoSelect"
ng-init="carregarObjeto()" ng-model="objeto"
class="form-control"
placeholder="<spring:message code="label.objeto" />"
aria-describedby="basic-addon1"
ng-options="objeto.oid as objeto.descricao for objeto in list.objetos">
</select>
<span class="input-group-addon" id="basic-addon1">
<span class="glyphicon glyphicon-pencil"></span>
</span>
</div>
JavaScript :
$scope.carregarObjetos = function() {
$http({
method : "GET",
url : '<c:url value="/cadastros/objeto/getObjetos" />'
}).then(function mySuccess(response) {
var length = response.data.length;
var data = response.data;
for (var i = 0; i < length; i++) {
$scope.list.objetos.push({
oid : data[i].oid,
descricao : data[i].descricao.toString(),
label : data[i].modelo.label.toString()
});
}
}), function myError(response) {
alert("Não foi possível carregar lista de objetos");
}
}
Result :
Instead of displaying the numbers 3
and 5
in the two options
that comes from the database table, it is showing this way:
AndthedataisreceivedcorrectlyinAJAX
.
EDIT
Aoption
appearswithinselect
whenupdatingwithcarregarObjetos
method:
<optionvalue="? number:5 ?"></option>