typescript filtering

2

I need to make the function query "clients" be entered in the "getimtems" function to be able to filter the data Here I get the query:

clientes() {
    this.userData.accion="consultaclientes";
     this.restprovider.Registro(this.userData).then((result) => {
        this.data = result;
        console.log(this.data);
      }, (err) => {
        this.presentToast(err);
      });
  }

The result of the query I need to enter in this function:

getItems(ev) {

    this.clientes();

  var val = ev.target.value;

    // if the value is an empty string don't filter the items
    if (val && val.trim() != '') {
      this.result = this.result.filter((result) => {
        return (item.toLowerCase().indexOf(val.toLowerCase()) > -1);
      })
    }

  }

This is the query I do in php:

case 'consultaclientes':
  $nombre = $request->nombre;


    $sql2=("SELECT * FROM 'cliente' WHERE nombre = '$nombre'" );
    $resultado = $mysqli->query($sql2);
    //$row1= $resultado->fetch_array();

    $json_array= array();
    while($fila=mysqli_fetch_assoc($resultado)){
       $json_array[]=$fila;
    };

    echo json_encode($json_array);
                exit(0);

 break;
    
asked by Ronald López 30.09.2018 в 21:13
source

1 answer

0

As I understand you need to filter your query result

you can use the following

public function llamadoDatos(){

return this.userData.accion="consultaclientes";
     this.restprovider.Registro(this.userData).then((result) => {
        this.data = result;
        console.log(this.data);
        return this.data;
      }, (err) => {
        this.presentToast(err);
      });
}

and in the filtering function put something similar to the following

public async getItems(ev): items[] {

 try {
  let datos = await this.llamadoDatos();
} catch(error: any) {
 console.error(error);
}
  var val = datos.value;

    // if the value is an empty string don't filter the items
    if (val && val.trim() != '') {
      this.result = this.result.filter((result) => {
        return (item.toLowerCase().indexOf(val.toLowerCase()) > -1);
      })
    } else {
  return val
}

  }

I hope it's your help Health.

    
answered by 15.01.2019 в 13:05