Observables
Knockout is built around three core features:
- Observables and dependency tracking
- Declarative bindings
- Templating
Model-View-View Model (MVVM) is a design pattern for building user interfaces. It describes how you can keep a potentially sophisticated UI simple by splitting it into three parts:
-
A model: your application’s stored data. This data represents objects and operations in your business domain (e.g., bank accounts that can perform money transfers) and is independent of any UI.
-
A view model: a pure-code representation of the data and operations on a UI.
-
A view: a visible, interactive UI representing the state of the view model.
<script type='text/javascript' src='knockout-3.2.0.js'></script> My name is <span data-bind="text: name"></span>, <span data-bind="text: age"></span> years old <script> //ViewModel var myViewModel={ name:ko.observable('allen'), age:ko.observable(25) }; //writing observable myViewModel.name('Mary').age(50); //applyBindings ko.applyBindings(myViewModel); //event myViewModel.name.subscribe(function(newValue) { alert("The person's new name is " + newValue); }); //writing observable myViewModel.name('alisa').age(25); </script>
http://blog.csdn.net/eqera/article/details/8437349
Stay hungry, stay foolish