Skip to content

Instantly share code, notes, and snippets.

@msh9
Created May 18, 2014 16:08
Show Gist options
  • Save msh9/22ad16537e18a5e50bac to your computer and use it in GitHub Desktop.
Save msh9/22ad16537e18a5e50bac to your computer and use it in GitHub Desktop.
Very simple usage of Ko and select element
<!DOCTYPE HTML>
<head>
<title>A Knockout select example</title>
<script src="http://ajax.aspnetcdn.com/ajax/knockout/knockout-3.0.0.js" type="text/javascript"></script>
<script type="text/javascript">
var vm = function() {
var self = this;
self.myList = ko.observableArray();
self.myList.push('Option 1');
self.myList.push('Option 2');
self.myList.push('Option 3');
}
if (window.addEventListener) {
window.addEventListener('load', function() {
var viewModel = vm();
ko.applyBindings(viewModel);
}, false);
} else if (window.attachEvent) {
window.attachEvent('onload', function () {
var viewModel = vm();
ko.applyBindings(viewModel);
});
}
</script>
</head>
<body>
<select multiple='multiple' data-bind="options: myList"></select>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment