-1

I have an form wth autocomplete, it does work well in local but when i compile it to pwa it is not filtering datas. The api works well and return a data json array response

     var normalize = function (term) {
          var ret = "";
          for (var i = 0; i < term.length; i++) {
            ret += accentMap[term.charAt(i)] || term.charAt(i);
          }
          return ret;
        };

 search(Objobs: { Objobs?: any; id?: any; }, filter: { name: string } = { name: '' }, page = 1): Observable<IUserResponse> {

     return this.http.get<IUserResponse>('https://tutututu.com/agriobs-codeigniter/index.php/structure/get_area/17' ).pipe(
          tap((response: IUserResponse) => {
            response.results = response.results
              
           // Not filtering on mobile device (Android, Ios) ! 
              .map(user => new User(user.id_commune, user.nom_commune))
              .filter(user => normalize(user.nom_commune.toLowerCase()).includes(filter.name))
    
               return response;
               //console.log(response); 
          })
        )
}

2 Answers2

0

The return value of the Lambda you pass to tap is ignored as tap does not alter the values in a stream. Also, it's not clear where filter.name comes from.

I would change tap to map. That might look like this:

return this.http.get<IUserResponse>('https://tutututu.com/agriobs-codeigniter/index.php/structure/get_area/17' ).pipe(
  map((response: IUserResponse) => {
    response.results = response.results
      .map(user => new User(user.id_commune, user.nom_commune))
      .filter(user => normalize(user.nom_commune.toLowerCase()).includes(filter.name))
    return response; 
  })  
);
Mrk Sef
  • 7,557
  • 1
  • 9
  • 21
0

Sorry it is a diacritic autocomplete conversion problem !