【发布时间】:2013-04-28 07:57:33
【问题描述】:
我通过向引导程序传递一个简单的平面 json 字符串数组(如 ["php","php4","php5"])来进行预输入工作。在这种情况下,所有标准函数都可以满足我的要求。
但是我想以如下格式提供数据:
[
{
"name":"php",
"count":123
},
{
"name":"php4",
"count":3532
},
{
"name":"php5",
"count":999
}
]
因此,我想格式化我的预输入以同时使用名称和计数。也许会产生一些看起来像 php5 (999) 的东西,当你选择 typeahead 时,它只会输出 php5。我想如果我只是覆盖所有的功能会很容易做到。
$('.input-classname').typeahead({
source: function (query, process) {
// Source here
},
updater: function (item) { // What gets sent to the input box
return item.name;
},
highlighter: function(item) {
return item.name + " (" + item.count + ")";
},
matcher: function (item) {
// Do the matching
},
sorter: function (items) {
// Do the sorting
}
});
这很好用,但我想使用highlighter、matcher 和sorter 的base 版本来完成繁重的工作。我只是传入item.name 而不是item。但是我不知道如何获得这些功能的基本版本。有没有办法做到这一点?
【问题讨论】:
标签: javascript json twitter-bootstrap bootstrap-typeahead