Greg
Greg

Reputation: 6633

knockout.js - how to set visiblity of an <option> in a select that is populated with data-bind='options: [...]'

I have a situation where I have something like:

<select data-bind='options: [...], optionsText: "foo", optionsValue: "bar"'></select>

this is populating my select as expected. Is it possible to also set the visibility of the generated options based on some condition?

Upvotes: 0

Views: 67

Answers (1)

Tom W Hall
Tom W Hall

Reputation: 5283

I would suggest adding a computed function on your view model which returns the required set, filtered with something like Underscore.js's filter function (or built however your logic dictates). Then bind to that function as the options parameter on the binding.

Upvotes: 1

Related Questions