I am using knockout.js. I am stuck in a little bit strange situation ( its hard to explain but i am trying, sorry if i am not clear ). I am using custom binding and options binding on a single select-list :
<select data-bind="options : arrayOfOptions, optionsText: 'Name',
optionsValue: 'Name', chosen: { }">
</select>
ko.bindingHandlers.chosen = {
init: function (element, valueAccessor, allBindingAccessor,
viewModel, bindigContext) {
var options = ko.utils.unwrapObservable(valueAccessor() || {});
$(element).chosen(options);
}
};
Here at runtime selectlist will fill with all available options from the arrayOfOptions array and chosen is a custom binding in which i am applying a CHOSEN PLUGIN on the select-list.
Now the problem i am facing here is that in custom binding when i applied choose plugin on select list at that time the selectlist is not filled with the options from the arrayOfOptions array. Means in a simple term the custom binding is executing before options binding. Can anybody please give me a solution for this so that custom binding applied after options binding?
Move your call to
choseninto the update.http://jsfiddle.net/jearles/avSfa/28/
—
—
Alternatively, you can use
setTimeoutto move the call tochosento the bottom of the execution queue. This will give the Knockout options binding time to do its work beforechosentries to transform it.