Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Knockout: valueAccessor vs viewModel on custom binding handlers?

Tags:

knockout.js

What's the difference between getting access to a view model's values through the binding properties (via valueAccessor) and getting them from the viewModel argument passed to the handler's init and update? I have always assumed the answer is that those model properties linked to valueAccessor automatically set up bindings (which would fire an update on any change to observables) but I'm not sure about that.

like image 858
neverfox Avatar asked Jul 04 '13 19:07

neverfox


1 Answers

The valueAccessor argument gives you access to specifically what was passed into the binding, while the viewModel argument gives you access to the entire data object at the scope.

So, if someone says text: firstName

valueAccessor() would give you the firstName observable/property and viewModel would give you access to the object that contains firstName.

like image 95
RP Niemeyer Avatar answered Sep 28 '22 06:09

RP Niemeyer