【发布时间】:2015-12-21 14:59:39
【问题描述】:
我正在使用带有 Iron Router 的 Meteor,但似乎无法提前输入(此版本:https://github.com/bassjobsen/Bootstrap-3-Typeahead)。
这里有一些代码:
HomeController = RouteController.extend({
//....
after: function () {
var tags = this.getData().tags;
console.log(tags);
if(tags.length > 0) {
var tags = ['hello', 'world'];
console.log("Adding typeahead for tags to ", $('.input-search')[0]);
console.log("tags: ", tags);
$('.input-search').typeahead({
source: tags,
updater: function(item) {
Router.go('/projects/tag/' + item);
}
});
}
},
我有一个作为应用程序布局一部分的标题,并且有这样的输入:
<input type="text" class="form-control input-search" data-provide="typeahead" placeholder="Search">
after: 函数中的 jQuery 正确获取输入。但是在输入上调用 typeahead 似乎并没有正确激活 typeahead:在输入中输入时,什么也没有发生。
但是,如果我将 typeahead 调用包装在 setTimeout 中,它确实有效。
当然,每当你开始在 setTimeouts 中包装东西时,就会出现一些问题。
使用 Iron Router 时,在哪里/何时是初始化 typeahead 的正确位置?
【问题讨论】:
标签: meteor bootstrap-typeahead iron-router