RKNirvana
RKNirvana

Reputation: 75

Knockout Select Options Binding Callback After Items Are Rendered

Is there any method/work around by which we can execute a callback function after binding all options of a Knockout Bound Select Control?

Upvotes: 0

Views: 1840

Answers (1)

dfperry
dfperry

Reputation: 2258

See http://knockoutjs.com/documentation/options-binding.html the property you want is called optionsAfterRender.

For example, when binding to a list of objects with 'display' and 'value' fields, you can disable options with no value set (placeholder options, for example) with the following:

<select data-bind="
            options: options,
            optionsText: 'display',
            optionsValue: 'value',
            value: value,
            optionsAfterRender: function(option, item) {
                ko.applyBindingsToNode(option, {disable: item.value == null && !optional}, item);
            }"></select>

Upvotes: 1

Related Questions