I’m new to Knockout and even though I’ve used an observable pattern library before, I don’t know how to set a function to observe a value in the ViewModel and to trigger when that value changes.
The situation is like this:
I’d like a modal popup to be enabled when the value of a dropdown is “other”. I’m using the Twitter bootstrap “dropdown” (which is really a list of anchors) and each anchor has a click binding to a function on the ViewModel called setDetail. setDetail sets the value of an observable property called problem.
My thinking is to put a function to observe the value of problem in order to keep the logic separate. Is there a way to do this or should I put the code in the setDetail function?
Any help is appreciated!
Yes, you can explicitly subscribe to an observable.
The documentation is available here, search for Explicitly subscribing to observables.
You would be doing something like: