I have some data which I am binding to a dropdown dynamically like this:
if (product.oPTIONS.length > 0) {
$.each(product.oPTIONS, function (idx, options) {
/*appending the each option to a label*/
$("#productdetails").append('<div class="clear">');
$("#productdetails").append('<label>' + options.OptionName + '</label>');
if (options.values.length > 0) {
var stringBuilder = [];
/*Creating a select tag for the Retrieved options*/
$("#productdetails").append('<select id="' + options.OptionName + '" onchange="getimage($(this).val())" ><option>Choose</option>');
$.each(options.values, function (idx, values) {
/*Binding options to the Created select tag For an Option based on option Id*/
$("" + "#" + options.OptionName + "").append('<option value="' + values.sku + '">' + values.OptionValue + '</option>');
});
stringBuilder.push('</select>');
$("#productdetails").append(stringBuilder.join(''));
}
$("#productdetails").append('</div>');
})
}
Now my situation is that some of the values of a drop down may be repeated in that case only one value should be bound to the drop down.
example
Size:DropDown
[S]
[XXl]
[s]
[xl]
Fit:DropDown
[Slim]
[Regular]
[Slim]
[AppleCut]
This is the case, here I want to bind only [S],[Slim] in size,Fit dropdowns only once.
Add the options to an array as they are considered for inclusion in the select, checking for their existence against that array before inclusion:
See: http://api.jquery.com/jQuery.inArray/