3

我正在使用带有自定义模板和 Bootstrap css文件的 Bloodhound 预输入。我的模板与上面的第一个链接一样,如下所示:

$(function() {

    cropsSuggestionEngine.initialize();

    $('#select-crop .typeahead').typeahead({
        hint: true,
        highlight: true,
        minLength: 1
    }, {
        name: 'Gewassen',
        displayKey: 'name',
        source: cropsSuggestionEngine.ttAdapter(),
        templates: {
            empty: ['<div class="empty-message">','Niets gevonden...','</div>'].join('\n'),
            suggestion: Handlebars.compile('<p><strong>{{name}}</strong> in {{category}}<br/>'
                                         + 'Ras: {{race}}.<br/>'
                                         + '<i>Groeitijd: {{growingTime}} maanden.</i><br/>'
                                         + '<input type="hidden" name="selected-crop-id" value={{id}}></p>')
        }
    }); 

});

不幸的是,模板中匹配的所有元素都会被高亮显示,因为它们在被选中时会获得“tt-highlight”css 类。看:

突出显示的问题

在页面的 HTML 中会发生这种情况:

Groeitijd: 2 m
<strong class="tt-highlight">a</strong>
<strong class="tt-highlight">a</strong>
nden.

我不希望Groeitijd: {{growingTime}}对模板中的部分进行这种突出显示。我知道如何删除所有突出显示,但不适用于模板中的特定部分。

有谁知道如何做到这一点?非常感谢。

4

1 回答 1

4

通过向我不想突出显示的部分添加一个不突出显示的类来修复它,如下所示:

<i class="no-highlighting">Groeitijd: {{growingTime}} maanden.</i><br/>

由于突出显示意味着strong在匹配的部分周围添加,我们通过添加以下 CSS 为该元素赋予了非粗体外观:

.no-highlighting strong {
    font-weight:normal;
}
于 2015-02-13T13:05:33.550 回答