knockout.js foreach (template for dropdown)
Current example shows you how to display dropdowns as many as you have items in your array using foreach() and ko.templates
HTML
<script src="http://cloud.github.com/downloads/SteveSanderson/knockout/knockout-2.2.0.js"></script>
<div data-bind="template: { name: 'myTemplate', foreach: values}">
</div>
<script id="myTemplate" type="text/html">
<select data-bind="options: $root.values, optionsCaption: 'Choose..'"></select>
</script>
CSS
span select{
margin-right: 20px;
}
JavaScript
var viewModel = function(data) {
var self = this;
self.values = ko.observableArray([ "Item 1", "Item 2", "Item 3", "Item 4"]);
};
ko.applyBindings(new viewModel());