Reputation: 4124
I would like to replace whole content in my selectbox.
Here's what I have:
My new content looks like:
[Object, Object, Object]
0: Object
Label: "A"
Value: 1
1: Object
Label: "B"
Value: 2
and I tried replace it this way:
var $el = $("#mySelectBoxId");
$el.empty();
$.each(newOptions, function (value, key) {
$el.append($("<option></option>")
.attr("value", value).text(key));
});
And the result looks like list of Objects.
Upvotes: 1
Views: 26
Reputation: 36147
Try like this,
var $el = $("#mySelectBoxId");
$el.empty();
$.each(newOptions, function(idx,item) {
$el.append($("<option/>").attr("value", ""+item.Value+"").text(item.Label));
});
Upvotes: 1