I am trying to trigger Typeahead when i populate the search box from my knockout view model function.
Here is a js Fiddle that demonstrates my problem. When i click on the submit button the search field gets populated with the word 'apples' but typeahead does not get triggered.
<div>
<input id="btnSearch" data-bind='value: search'>
<br>
<button id="btnSubmit">Send String to Search Box From Here</div>
function ViewModel() {
this.search = ko.observable("");
this.call = function () {
this.search('apples');
}
}
vm = new ViewModel();
var data = ["apples", "bananas", "peaches"];
$("#btnSearch").typeahead({
source: data
});
$("#btnSubmit").click(function () {
vm.call();
});
ko.applyBindings(vm);
Trigger the typeahead with typeahead instead of val()
$('#searchVendor').typeahead('setQuery', 'value-you-want-to-set');
or better yet
jQuery#typeahead('setQuery');
I would interpret this in your code as -
$#searchVendor(myValue()); || $#searchVendor('mike');
It is a GitHub'd issue https://github.com/twitter/typeahead.js/issues/247
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.