预先输入图像

时间:2014-07-04 16:00:01

标签: javascript jquery json twitter-bootstrap typeahead

一直在寻找使用typeahead + bloodhound v0.10.2找到将结果添加到结果中的解决方案。没有什么真正记录如何在最新版本中执行此操作,并且文档与图像无关。我的设置很简单,我从JSON调用结果。在我的结果中,我有一个img src,我想将其添加到typeahead结果中。

1。这种类型甚至可以用于预先输入并且效果如何吗?

2。该网站有大约2000多种产品,是打算处理这个问题的先行者还是应该考虑使用其他产品?

这是我的设置:

var TTproducts = new Bloodhound({
    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('product'),
    queryTokenizer: Bloodhound.tokenizers.whitespace,
    prefetch: 'json_seeds/product.json'
});

TTproducts.initialize();

$('#the-basics .tt').typeahead({
    highlight: true
}, {
    name: 'products',
    displayKey: 'product',
    source: TTproducts.ttAdapter(),
    templates: {
        empty: [
            '<div class="empty-message">',
            'unable to find any Best Picture winners that match the current query',
            '</div>'
        ].join('\n'),
        header: '<h4>PRODUCTS</h4><hr>',
        suggestion: Handlebars.compile('<img src="{{img}}" width="25px"> {{product}}')
    }
});

JSON:

[{
    "product": "Red T-shirt",
    "img": "img_seeds/products/1.jpg"
}, {
    "product": "Blue T-shirt",
    "img": "img_seeds/products/2.jpg"
}, {
    "product": "White T-shirt",
    "img": "img_seeds/products/3.jpg"
}]

修改

出于某种奇怪的原因,上述内容适用于Safari和Firefox,但不适用于chrome。有什么想法吗?

0 个答案:

没有答案