I am trying the bind a dropdown list in knockout js, but in my data there are some duplicates is it possible remove these duplicates while binding to the dropdown list?
Here is how i bind the data
<select data-bind="options: availableCountries,
optionsText: function(item) {
return item.countryName + ' (pop: ' + item.countryPopulation + ')'
},
value: selectedCountry,
optionsCaption: 'Choose...'"></select>
var Country = function(name, population) {
this.countryName = name;
this.countryPopulation = population;
};
and my viewmodel is as below
var AppViewModel = function() {
this.availableCountries = ko.observableArray([
new Country("UK", 65000000),
new Country("USA", 320000000),
new Country("Sweden", 29000000),
new Country("Sweden", 29000000)
]);
this.selectedCountry = ko.observable();
};
ko.applyBindings(new AppViewModel());
Here is the js fiddle http://jsfiddle.net/PV7yD/
Thanks,
Praveen.