Another complete Noob question about KnockoutJS I’m afraid…
I understand the Observables feature, in that if the viewmodel changes, then UI elements which are bound to the viewmodel will also change to reflect this.
So the UI is reacting to the viewmodel.
In my application, to change the viewmodel, I need to make an AJAX call to the server. How do I bind that server request to a change in UI.
Normally I’d just use jquery
$("[#HolidayDestination").change(function () {
// Make Ajax call
});
Do I still continue to work that way with KnockoutJS?
There are a couple of ways to handle this situation, but the basic idea is that you want the triggers for your AJAX requests to come from changes to your view model.
If you want to trigger an AJAX request based on the change to a single observable, then a manual subscription is a good choice.
If you want to trigger it based on a change to several observables, then you can wrap it in a dependentObservable. In this case, the dependentObservable does not even need to return a value. You just wouldn’t bind to it in your UI and it would be used purely as a trigger.