knockout.js - Twitter typeahead with Bloodhound doesn't refresh list with Knockout binding -
this may tricky 1 - i'm trying use twitter typeahead bloodhound engine , custom knockout binding. in example, have 2 lists of athletes (football , soccer). i'm using typeahead select athlete 1 of lists , i'm using dropdown select list pull from.
once sport selected dropdown, bloodhound engine initialized appropriate athletes , typeahead created. when sport changed, new bloodhound engine created new list of athletes. problem typeahead still using first list of athletes instead of new list.
i've debugged through , know bloodhound engine gets recreated new list, , twitter typeahead gets updated source. alas, old list comes when used. submit fiddle evidence - never mind style, is work in progress. briefly explain code:
at top athletetypeahead
class, custom athletetypeahead
binding (directly following class) creates initialize suggestion engine , typeahead. @ bottom view model, creates 2 different lists of athletes. debugging , sanity, i've displayed full list of selected athletes in view , sent list console.log
whenever new bloodhound suggestion engine created - both lists update correctly. i've tried calling clear()
, clearprefetchcache()
when creating new engine, though it's new engine, no luck there either. thoughts?
add $(element).typeahead('destroy')
athletetypeahead
constructor, i.e.
var athletetypeahead = function(athletes, element) { $(element).typeahead('destroy'); this.athletes = athletes; this.element = element; };
you can not create new typeahead on element has one, must dispose of first. save reference bloodhound engine somewhere, , use clear
, add
functions update engine without need destroy , reinitialize entire typeahead.
Comments
Post a Comment