如何在TypeaheadJS中使用局部变量对象和模板?

时间:2015-10-26 03:34:09

标签: javascript jquery twitter-bootstrap typeahead.js

我正在尝试使用Typeahead.js来创建网站支持部分中可用的文章列表。我已经能够使用以下方法使Typeahead.js工作:

var articles = ['Test','Test 2','Article'];

var posts = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.whitespace,
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    local: articles
});

$('#search .typeahead').typeahead({
    hint: true,
    highlight: true,
    minLength: 1
},
{
    name: 'posts',
    source: posts
});

这个问题是我无法将url传递给结果......我正在尝试使用这样的数组:

var articles = [{name: 'test', url: 'http://www.example.com'}];

这样我就可以将文章的网址与其名称相关联。当我将数据集更改为该格式时,显然该函数不再有效,因为它无法解释我的数据。

一旦我使阵列工作,我希望使用Typeaheads模板函数输出结果如下:

<a href="Object Url">Object Name</a>

有关如何修复函数以使用对象数组然后应用模板格式化结果的任何想法?

0 个答案:

没有答案