mryellow / knockoutjs-tokenfield

Bootstrap-tokenfield KnockoutJS custom binding
MIT License
6 stars 0 forks source link

valueAccessor() fails to set values #2

Open mryellow opened 9 years ago

mryellow commented 9 years ago

One-way binding seems fine but when we try to set values in the parent apps bound model they trigger update, this then fails as the refreshAll() function isn't on this valueAccessor().

Using the arrays the way I have is really the wrong way to use KnockoutJS.

The CSV remains an issue unless it's handed off to the client end to process, tokens haven't actually saved the id and other fields that were returned from AJAX as suspected, only value and label is available after the initial token creation.

Working on a solution that can pass everything straight through to the bound valueAccessor() while still dealing with flat CSV style return into non-array observables.

mryellow commented 9 years ago

Making specific updates in a custom binding

When creating a custom binding, typically the update function is used to track any dependencies that should trigger the function to be called again. Usually this is to respond to view model changes and make corresponding updates to the user interface. Internally, Knockout actually uses a computed as the mechanism to track these dependencies. In some cases, you may need more control over what triggers an update and the exact code that is executed to respond to an update. Perhaps you have multiple observable options, and want to perform different updates to the bound element when either change. In this scenario, in the init function, you can create one or more computeds to handle changes specific to each option.

https://blog.safaribooksonline.com/2014/02/19/getting-knockout-js-computed-observables/