Example 11
Here we see many cool KO components - such as applying bindings to a section of the page and it's descendents
For ref:
http://knockoutjs.com/documentation/observables.html
- Make:
- Model:
- Car:
Your Selections
selectedMake:
selectedModel:
selectedCar:
Example 2
We see here we can pass to a checked binding an observable array - and the checkbox will be cheked if the observable array containes the value
For ref:
http://knockoutjs.com/documentation/computed-writable.html
Produce
Example 3
Validation
Enter a numeric value:
That's not a number!
(Accepted value: )
Example 4
For each
http://knockoutjs.com/documentation/foreach-binding.html
Using $index, $parent, and other context properties
People
- Name at position : using $data: Remove
Example 5
Using “as” to give an alias to “foreach” items
categories: ko.observableArray([
{ name: 'Fruit', items: ['Apple', 'Orange', 'Banana'] },
{ name: 'Vegetables', items: ['Celery', 'Corn', 'Spinach'] }
])
-
:
Example 6 ko mapping from api and mapping to custom view model
Using Mappings plugin!
http://knockoutjs.com/documentation/plugins-mapping.html
see section for: Specifying the update target
And:
var viewModel = ko.mapping.fromJS(jsObj);
var viewModel = ko.mapping.fromJSON(JsonString)
We'll ask for Json to map from my API
http://itaiwebapi.apphb.com/api/expensegroups/1
http://itaiwebapi.apphb.com/api/expensegroups