I\'m generating a datalist
options based on a ko observable.
function Company(company) {
this.id = company.Id;
this.name = company.Name;
would you like something like this?
HTML
JAVASCRIPT
var Company = function (company) {
this.id = company.Id;
this.name = company.Name;
this.state = company.State.name;
}
var viewModel = {
selectedCompany: ko.observable(),
companies: ko.observableArray()
};
for(var x = 0; x<5; x++){
viewModel.companies.push(new Company({Id: x, Name:'name' + x, State: { name: 'namestate' + x}}));
}
ko.applyBindings(viewModel);
Knockout has already some options to create this selects.. see it in documentation http://knockoutjs.com/documentation/options-binding.html
http://knockoutjs.com/documentation/options-binding.html