Typeahead insensitive accent

前端 未结 3 482
悲哀的现实
悲哀的现实 2020-12-04 02:37

I tried this solution but I got this error :

Uncaught ReferenceError: normalized is not defined

Here is my code :



        
3条回答
  •  一整个雨季
    2020-12-04 03:10

    Change your normalize function so that it returns the normalized string i.e.

    var normalize = function (input) {
     $.each(charMap, function (unnormalizedChar, normalizedChar) {
        var regex = new RegExp(unnormalizedChar, 'gi');
        input = input.replace(regex, normalizedChar);
     });
     return input;
    }
    

    See this fiddle I wrote to see it working:

    http://jsfiddle.net/Fresh/SL36H/

    You can see the normalized string in the browser debug console. In my example "àààèèèùùù" is converted to "aaaeeeuuu".

    Note that I've changed the function parameters so that they are more accurate (i.e. chars is incorrect, it should be char) and I've also rationalised the regular expression.

提交回复
热议问题