Twitter Boostrap TypeAhead を MVC4 と共に使用する - 検索ボックスにあるものとは対照的に、検索ボックス内の任意の単語を強調表示するために、先行入力用の JavaScript を変更する方法はありますか? Outlook と入力すると、ドロップダウンの 4 つの項目で Outlook が強調表示されます。
ただし、「outlook access」(上記の 4 番目の項目に表示されます) と入力すると、コントローラーから JSON で返されますが、「Outlook access」はエントリに 1 つの文字列として表示されないため、TypeAhead には表示されません。 :
答えはここ(typeahead JS)にあると思いますが、確かではありません:
, highlighter: function (item) {
var query = this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&')
return item.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) {
return '<strong>' + match + '</strong>'
})
}
, render: function (items) {
var that = this
items = $(items).map(function (i, item) {
i = $(that.options.item).attr('data-value', item)
i.find('a').html(that.highlighter(item))
return i[0]
})
items.first().addClass('active')
this.$menu.html(items)
return this
}
助けてくれてありがとう、
マーク