Created
May 18, 2014 16:08
Very simple usage of Ko and select element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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