Last active
August 29, 2015 13:57
-
-
Save ccorcos/9677078 to your computer and use it in GitHub Desktop.
Bootstrap 2 typeahead with Meteor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I spent way too long trying to get this to work. | |
Template.search.events({ | |
'keyup input#search': function(e, t) { | |
if (e.keyCode == 13) { | |
// if the user presses enter to select a typeahead | |
var node = Nodes.findOne({ | |
title: e.target.value | |
}); | |
if (node) { | |
selectNodeOrLink("circle", node._id); | |
} | |
} | |
} | |
}) | |
Template.search.rendered = function() { | |
// intialize bootstrap typeahead | |
var autocomplete = $('input#search').typeahead(); | |
// autorun typeahead data source update | |
Deps.autorun(function() { | |
titles = function() { | |
return _.uniq(_.pluck(Nodes.find().fetch(), 'title')); | |
} | |
autocomplete.data("typeahead").source = titles(); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment