[英]How to create autocomplete which only starts with either first letter or any other letter in the string starting after space
In this fiddle autocomplete if I type letter "s" it shows listing which starts with "s" but I need all the listing starting with "s" and having space before "s". 在这个自动完成的小提琴中,如果我输入字母“ s”,它会显示以“ s”开头的列表,但我需要所有以“ s”开头且在“ s”之前有空格的列表。
Means if I type "s" then i should get both kind of results like "suraj kumar" & "nimish shah". 意味着如果我键入“ s”,那么我应该同时获得“ suraj kumar”和“ nimish shah”之类的结果。 Please someone suggest me solution.
请有人给我建议解决方案。
jsfiddle.net/9R4cV/701/
I'm not a RegExp guru, so there might be more clever solutions, but here's an updated fiddle: http://jsfiddle.net/9R4cV/702/ 我不是RegExp专家,所以可能会有更多聪明的解决方案,但是这里有更新的小提琴: http : //jsfiddle.net/9R4cV/702/
source: function(req, responseFn) {
var re = $.ui.autocomplete.escapeRegex(req.term);
var matcher = new RegExp( "^" + re, "i" );
var matcher2 = new RegExp( "\\s" + re, "i" );
var a = $.grep( aTags, function(item,index){
return matcher.test(item) || matcher2.test(item);
});
responseFn( a );
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.