【问题标题】:ajax, php and twitter's bootstrap typeaheadajax、php 和 twitter 的 bootstrap typeahead
【发布时间】:2013-07-20 08:47:08
【问题描述】:

好的,所以我正在尝试填充 twitter 引导程序的 typeahead,我遵循了这个答案: Twitter bootstrap Typeahead to populate 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 的警报,它发回 undefined... 为什么会这样?

谢谢, 阿拉

【问题讨论】:

  • return ~item.title.toLowerCase()... 所以~item 是错字吗?
  • 我拿走了〜,但它发送相同的错误消息......

标签: php jquery bootstrap-typeahead


【解决方案1】:

如果您的 Typeahead source 中的项目是对象,您将不得不跳过一些障碍。否则,您将收到该错误,因为 Bootstrap Typeahead 尝试在内部调用 toLowerCase() 来比较项目、排序项目等。

我不久前发表了一篇关于如何做到这一点的博文:http://victorblog.com/2013/06/21/how-to-use-rich-objects-and-typed-objects-with-bootstrap-typeahead/

我确定您根本没有覆盖 Typeahead 的 updater 函数。

【讨论】:

  • 我不太清楚你的意思...我拿出了匹配器、分类器和高亮器,并且预输入工作正常。但它显示了整个数组... {"href":1,"name":"The1Prodigy1"}
  • Nvm,我想通了!
  • 您能否准确分享您需要添加或更改以使其正常工作的内容? :)
猜你喜欢
  • 2012-03-03
  • 1970-01-01
  • 2014-05-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-03
相关资源
最近更新 更多