I am completely stumped. I think this should be an easy task yet it completely evades me. I am trying to just create a select list but for some reason this isn’t binding. I get no errors in the Console.
Here is my Javascript
var data = {
"StoreList": [{
"StoreNo": "02",
"StoreName": "Store02"
}, {
"StoreNo": "03",
"StoreName": "Store03"
}, {
"StoreNo": "14",
"StoreName": "Store14"
}, {
"StoreNo": "15",
"StoreName": "Store15"
}]
};
var viewModel = {};
viewModel = ko.mapping.fromJS(data);
ko.applyBindings(viewModel);
Here is my HTML
<select height="20" data-bind="options: viewModel.StoreList, optionsText: 'StoreName'"></select>
My fiddle http://jsfiddle.net/S7cqp/3/
You shouldn’t put
viewModelinto the data-bind attribute. It is just a name of the variable where your VM is stored. Your binding should look as follow:Here is a working fiddle: http://jsfiddle.net/vyshniakov/S7cqp/8/