【问题标题】:Typeahead/Bloodhound turn results into linksTypeahead/Bloodhound 将结果转换为链接
【发布时间】:2014-09-15 09:40:09
【问题描述】:

我正在关注这个http://twitter.github.io/typeahead.js/examples/#multiple-datasets,然后使用远程从数据库中检索数据使其工作。现在我想把结果变成链接,就像当你点击一个结果时,它会重定向到另一个名为 view.php?id=# 的页面。该怎么做?

Update1:所以我尝试了 Handlebars,但我不知道为什么它不起作用。下面是我的代码。我还不介意 id 因为我的代码不起作用。我先测试了这个名字。

var searchResult = new Bloodhound({
        datumTokenizer: function (d) {
        return Bloodhound.tokenizers.whitespace(d.name);
       },
        queryTokenizer: Bloodhound.tokenizers.whitespace,
        remote: {
            url: 'data.php?q=%QUERY',
            filter: function (results) {
                return $.map(results, function (result) {
                    return {
                       name: result.cl_fname
                    };
                });
            }
        }
    });

    searchResult.initialize();

    $('#multiple-datasets .typeahead').typeahead({
    hint: true,
    highlight: true
    },
    {
        name: 'cl-name',
        displayKey: 'name',
        source: searchResult.ttAdapter(),
        templates: {
        empty: [
            '<div class="empty-message">',
            'Cannot find.',
            '</div>'
        ].join('\n'),
        suggestion: Handlebars.compile('<p><strong>{{name}}</p>')
        }
    });

【问题讨论】:

    标签: typeahead.js bloodhound


    【解决方案1】:

    我现在开始工作了。我不知道 Handlebars 是一个不同的库,所以我想通了并下载了它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-08
      • 2020-09-05
      • 1970-01-01
      • 2017-12-03
      • 1970-01-01
      • 2014-03-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多