好吧,所以我试图在twitter的引导程序之前填充typeahead,我遵循了这个答案:Twitter引导Typeahead以填充hrefs
但我不断得到:
未捕获的类型错误:无法调用未定义编辑组的方法"toLowerCase"?id=14:239$.typeahead.matcher编辑组?id=14:239
这是它的代码:
matcher: function (obj) {
var item = JSON.parse(obj);
return ~item.title.toLowerCase().indexOf(this.query.toLowerCase())
},
我查看了网络选项卡,看看是否得到了正确的数据,我得到了这个:
0: {title:The1Prodigy1, href:1}
href: 1
title: "The1Prodigy1"
1: {title:test_suspend_user, href:4}
href: 4
title: "test_suspend_user"
2: {title:test_ban_user, href:5}
3: {title:test_delete_user, href:6}
4: {title:user_test_edit, href:7}
最后一个问题,我需要href吗?因为,我只想帮助用户键入正确的用户名。我不希望它被链接到另一个页面或任何东西。这是一种形式…
编辑:我添加了item.title的警报,它会发回未定义的。。。为什么?
谢谢,Ara
如果Typeahead source
中的项是对象,那么您将不得不跳过一些困难。否则,当Bootstrap Typeahead尝试内部调用toLowerCase()
以比较项目、排序项目等时,您将收到该错误。
不久前,我发表了一篇关于如何做到这一点的博客文章:http://victorblog.com/2013/06/21/how-to-use-rich-objects-and-typed-objects-with-bootstrap-typeahead/
我相信您根本没有覆盖Typeahead的updater
函数。