I have multiple input boxes that I want to hide/unhide based on a selection from user.
I can achieve this by having a separate dependentObservable for each input an
In Knockout, bindings are implemented internally using dependentObservables, so you can actually use a plain function in place of a dependentObservable in your bindings. The binding will run your function inside of a dependentObservable, so any observables that have their value accessed will create a dependency (your binding will fire again when it changes).
Here is a sample: http://jsfiddle.net/rniemeyer/2pB9Y/
html
type "one", "two", or "three":
js
var viewModel = {
text: ko.observable("one"),
items: [{name: "one"}, {name: "two"}, {name: "three"}],
};
viewModel.shouldThisBeVisible = function(name) {
return this.text() === name;
}.bind(viewModel);
ko.applyBindings(viewModel);