Reputation: 2733
I'm able to populate the names of option fields for the #maplist
select dropdown:
$.each(mapsArray, function(x,y) {
$.each(y, function(j,z) {
$('#maplist').append(
$('<option></option>').html(z.mapName)
);
});
});
But I can't figure out how to add .val
to each option field (in this case, it would be z.mapID.$id
)
Upvotes: 3
Views: 1040
Reputation: 50493
I would do it this way rather than concatenating a bunch of strings.
$.each(mapsArray, function(x,y) {
$.each(y, function(j,z) {
$('#maplist').append(
$('<option></option>').val(z.mapName).text(z.mapName);
);
});
});
Upvotes: 1
Reputation: 11615
Use .attr():
$.each(mapsArray, function(x,y) {
$.each(y, function(j,z) {
$('#maplist').append(
$('<option></option>').html(z.mapName).attr('value', z.mapID.$id);
);
});
});
Upvotes: 0
Reputation: 87073
$.each(mapsArray, function(x,y) {
$.each(y, function(j,z) {
$('#maplist').append(
$('<option value="'+ z.mapName +'">'+ z.mapName +'</option>');
);
});
});
Upvotes: 2