Bootstrap 3 için Bootstrap-3-Typeahead'u kullanabilirsiniz.
updater
ve matcher
işlevlerinin üzerine yazmak zorunda kalacaksınız.
updater: function (item) {
return this.$element.val().replace(new RegExp(this.query + '$'),'') + item + ',';
}
(eşleştirebiliriniz son bir oluşum: JavaScript: replace last occurrence of text in a string)
matcher: function (item) {
var last = this.query.split(',');
this.query = $.trim(last[last.length-1]);
if(this.query.length) return ~item.toLowerCase().indexOf(this.query.toLowerCase());
}
sizin update
için şu kodu kullanın: aşağıdaki gibi matcher
fonksiyonu için size değiştirmek işlevinden kodu kullanabilirsiniz Komple örnek:
$('.typeahead').typeahead (
{
items: 4,
source: function (query, process) {
states = [];
map = {};
var data = [
{"stateCode": "CA", "stateName": "California"},
{"stateCode": "AZ", "stateName": "Arizona"},
{"stateCode": "NY", "stateName": "New York"},
{"stateCode": "NV", "stateName": "Nevada"},
{"stateCode": "OH", "stateName": "Ohio"}
];
$.each(data, function (i, state) {
map[state.stateName] = state;
states.push(state.stateName);
});
process(states);
}
, updater: function (item) {
return this.$element.val().replace(new RegExp(this.query + '$'),'') + item + ',';
}
, matcher: function (item) {
var last = this.query.split(',');
this.query = $.trim(last[last.length-1]);
if(this.query.length) return ~item.toLowerCase().indexOf(this.query.toLowerCase());
}
}
);
c Ayrıca, ilk önce girişinizdeki tüm virgülle ayrılmış değerleri almanız ve bunları elde ettiğiniz veri kümesinden kaldırmanız gerektiğine de dikkat edin. Yinelenen izinleri planlamadığınız sürece öneriler listesini göstermek için son giriş değerini kullanmadan önce. Büyük olasılıkla otomatik tamamlamayı/ipucunu da devre dışı bırakmanız gerekecek mi? Tahminimden bu yana girişinizi etkileyecektir. – Pricey