Skip to content

Instantly share code, notes, and snippets.

@arisetyo
Created November 9, 2012 03:11
Show Gist options
  • Save arisetyo/4043479 to your computer and use it in GitHub Desktop.
Save arisetyo/4043479 to your computer and use it in GitHub Desktop.
Introduction to Knockout.js
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>hello-knockout-js</title>
</head>
<body>
<!-- syntax: data-bind="bindingName: bindingValue"-->
<p>Day: <input data-bind="value: dayOfWeek" /></p>
<p>To do: <input data-bind="value: activity" /></p>
<p>The day of the week is <span data-bind="text: dayOfWeek"></span>, so it's time for <span data-bind="text: activity"></span></p>
<script type='text/javascript' src='knockout-2.1.0.js'></script>
<script type='text/javascript'>
function viewModel() {
this.dayOfWeek = ko.observable('Monday');
this.activity = ko.observable('getting stuck in traffic');
};
ko.applyBindings(new viewModel());
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment