use ion-select dynamically

Asked

Viewed 365 times

0

I put as options in ion-select, South zone, north, center and west. I want when I click on some option, to show only the information of that zone by taking the information from the database. At the moment I only have the same select.

<ion-item no-lines class="setaselect">
  <ion-label stacked color="carioca" >REGIÕES</ion-label>
  <ion-select>
      <ion-option value="opt1"></ion-option>
      <ion-option value="opt2">Zona Oeste</ion-option>
      <ion-option value="opt3">Zona Norte</ion-option>
      <ion-option value="opt4">Zona Sul</ion-option>

  </ion-select>

DB.ts

getRegiao(pregiao: string){
return new Promise<Regiao[]>((resolve, reject) => { 

  let sql = "select * from tb_regiao" + pregiao;
  console.log(sql);          
  this.executeQuery(sql).then(data => {
    let regioes = [];
    data.forEach(function (row) {
      let regiao: Regiao = { nom_regiao: row[0]}
      regioes.push(regiao);
    });
    resolve();

  }).catch(error => {
    console.log(error);
  });

});


}

and my function ts.

 selecionaregiao(pregiao: string) {
this.db.getRegiao(pregiao)
        .then(data => this.regioes = data)
        .catch(error => console.log('Something want wrong!'));
 }

But I don’t know exactly how I do it, nor can I research exactly what I want. As I am still learning, I decided to ask for this information here :D
If anyone knows how to do this, or any tutorial, I really don’t know how to do it.

  • You already know how to get the bank information or you need it too ?

  • i already use the sqlite database.. I have segment Buttons in my code, and clicking on them I already get the database information. I only want now when selecting the region, search only the database information of that region. I have already created the table and columns in the database. I only need to use in select :D now

  • I posted as an answer.

1 answer

0

It does a function that fetches the data and does the following in its component: Create an Ngmodel for your select and call a function by changing the data.

<ion-select (ionChange)="suaFuncao()" [(ngModel)]="regiao">
      <ion-option value="opt1"></ion-option>
      <ion-option value="opt2">Zona Oeste</ion-option>
      <ion-option value="opt3">Zona Norte</ion-option>
      <ion-option value="opt4">Zona Sul</ion-option>

  </ion-select>

In typescript does:

regiao: any; //Se tiver um tipo específico coloca ele

suaFuncao(){
    //Chama a função para buscar do banco de dados e passa this.regiao como parâmetro.
}
  • I’m getting the following error "core.js:1449 ERROR Error: no such table: tb_regiaoundefined at Database.webpackJsonp.318.Database.handleError " know how to tell me what might be? I’ll leave in my post my db and my function, if you can tell me what could be wrong. I’m still new with Ionic and database has been a bit tricky.

  • it seems your prerequisite variable is Undefined.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.