angularjs search and ignore spanish characters

前端 未结 5 1937
名媛妹妹
名媛妹妹 2020-12-15 14:03

I\'m adding a simple sort on a page. The idea is to search products. These products are written in spanish language and has accents. For example: \'Jamón\'.

Here is

5条回答
  •  隐瞒了意图╮
    2020-12-15 14:52

    Check here for solutions to filter a list of objects and search keywords in every property of every object. It also maintain angular like search and also search with/ without accent characters.

    Following is the filter definition:-

                    // ignore accents filter
                $scope.ignoreAccents = function (item) {
                    if (!$scope.search) return true;
                    var objects = [];
                    var jsonstr = JSON.stringify(item);
                    var parsejson = JSON.parse(jsonstr);
                    var searchterm = $scope.search.replace(/[!#$%&'()*+,-./:;?@[\\\]_`{|}~]/g, '');    // skip replace if not required (it removes special characters)
                    objects = getNoOfResults(parsejson, searchterm);
                    return objects.length > 0;
                };
    

提交回复
热议问题