简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM