I have a problem with observable plugin and custom binding. Observable plugin works great with standard binding. I have created typeahead custom binding, code below. The last part of the plugin is the problem, if the value is normal observable it works. But with observable plugin it doesn't because the property is not "normal" observable. How can I set the value for selectedItem with Observable plugin?
ko.bindingHandlers.typeahead = {
init: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
valueAccessor().initialize();
var selectedItem = allBindings.get('selectedItem');
var minLength = allBindings.get('minLength');
if (!minLength)
minLength = 3;
$(element).typeahead(
{
minLength: minLength,
highlight: true
},
{
name: 'best-pictures',
displayKey: 'Name',
source: valueAccessor().ttAdapter(),
templates: {
...
}
}).on('typeahead:selected',
function (event, suggestion, dataset) {
selectedItem(suggestion);
});
}
};
Usage
<input data-bind="typeahead: projectTasks, selectedItem: task"/>
where projectTasks is Bloodhound "datasource"