Ion-item and ion-select dynamic


#1

Guys, I’m new to IONIC and I have a problem.

I do not know how to get the information from this code. Exemple in [(ngModel)]=“todo”

I tried in many ways, but I could not do it.

Thank you all for your help.

And sorry for my English.

<form (ngSubmit)="logForm()">

    <button ion-button type="submit" block>Adicionar Destinatários</button>

    <ion-list>
      <ion-item *ngFor="let item of itens">
        <ion-label>{{item.title}}</ion-label>
        <ion-select multiple="true" okText="OK" cancelText="Cancelar" >
          <ion-option *ngFor="let itemsub of item.subcategoria">{{itemsub.titulo}}</ion-option>
        </ion-select>
      </ion-item>
    </ion-list>

  </form>
itens:any;  
todo = []

this.itens = [
      {
        id: '1',
        title: 'Categoria 1',        
        subcategoria :  [
                          { 
                            id: '1',
                            titulo:'Subcategoria 1'
                          },
                          { 
                            id: '2',
                            titulo:'Subcategoria 2'
                          },
                          { 
                            id: '3',
                            titulo:'Subcategoria 3'
                          }                          
                        ]
      },
      {
        id: '2',
        title: 'Categoria 2',
        subcategoria :  [
                          { 
                            id: '4',
                            titulo:'Subcategoria 4'
                          },
                          { 
                            id: '5',
                            titulo:'Subcategoria 5'
                          },
                          { 
                            id: '6',
                            titulo:'Subcategoria 6'
                          }                          
                        ]
      },
      {
        id: '3',
        title: "Categoria 3"
      }
    ];

#2

Sorry, this is not really explaining what you want to do.


#3

First, thank you for having responded.

What I want is to know how to put the result of what was selected for a variable.


#4

https://ionicframework.com/docs/api/components/select/Select/#multiple-value-checkboxes doesn’t work for you? Why not?


#5

I have the following problem:

I have an initial list json:

{
 "status": "success",
 "mensagem": "lista",
 "retorno": [
 {
 "id": "1",
 "title": "Categoria 1",
 "subintens": [
 {
 "id": "10",
 "titulo": "Sub 10"
 },
 {
 "id": "20",
 "titulo": "Sub 20"
 },
 {
 "id": "30",
 "titulo": "Sub 30"
 }
 ]
 },
 {
 "id": "2",
 "title": "Categoria 2",
 "subintens": [
 {
 "id": "100",
 "titulo": "Sub 100"
 },
 {
 "id": "200",
 "titulo": "Sub 200"
 },
 {
 "id": "300",
 "titulo": "Sub 200"
 }
 ]
 },
 {
 "id": "3",
 "title": "Categoria 3",
 "subintens": [
 {
 "id": "1000",
 "titulo": "Sub 1000"
 },
 {
 "id": "2000",
 "titulo": "Sub 2000"
 } ,
 {
 "id": "3000",
 "titulo": "Sub 3000"
 }
 ]
 }
 ]
}

Where I make a promise and put in “itens”

itens = [];
intensSelecionados = [];
 
Return promisse
this.itens = json.retorno;

on html

<form (ngSubmit)="logForm()" #loginForm="ngForm" >
 <ion-list>
 <ion-item *ngFor="let item of itens">
 <ion-label>{‌{item.title}}</ion-label>
 <ion-select multiple="true" okText="OK" cancelText="Cancelar" name="categoria" [(ngModel)]="intensSelecionados[item.id]">
 <ion-option *ngFor="let subintem of item.subintens" value="{‌{subintem.id}}"> {‌{subintem.id}} {‌{subintem.titulo}}</ion-option>
 </ion-select>
 </ion-item>
 </ion-list>
 </form>

So far so good, it is generated normally, the question is that I want to start selected some option. “Already tried with “selected” and does not work”, only worked with the example below partially.

Type with examples made:

Exemplo 1
this.intensSelecionados[1] = [10,30];
Exemplo 2
this.intensSelecionados[2] = [200,300];
Exemplo 3
this.intensSelecionados[3] = [2000];

If I put the examples separately it’s all right, but I want to put the example 1, 2 and 3, Together and it’s never always the last selected and never the ones I’m selecting.

Would you be able to help with this problem?

Thank you.