Closed 2piix closed 9 years ago
It took me a while to figure out this too, but Pager provides the callback
, and you're supposed to pass it the viewModel that you just loaded. The callback assigns the passed viewModel to the page's ctx
, so you can refer to the viewModel as $data
, or refer to its properties by their name directly in the HTML.
I'm using it with $.getJSON like this:
<div data-bind='page: {id: 'one', withOnShow: "$root.loadData(\"one\")"}'>
<span data-bind='text: $data'>
</div>
viewModel = {
loadData: function(id) {
return function(callback) {
$.getJSON(urlFor(id), function(data) {
callback(data);
}
}
}
}
Can we have documentation for "lazy bind view model" that does not depend on require.js? Using require.js to inject the code is troubling for many reasons, not least of which is the fact that I have to visit the github repo to find the source code for 'invention.js'. It is also troubling because it obscures the lesson. In particular, I find myself asking "What is that callback for? For Pager? For Knockout? For Require?"