lundi 28 janvier 2019

Is there a way to save the checked/ticked items into an array?

I have done a grid like this using the Checkbox plugin on the images, enter image description here

The data-items have been flagged description, checked/not-checked booleans, id's etc.

export const DATAITEMS: Array<DataItem> = [
{    id: 5451545, 
     name: "Chefs Collection",
     description: "This is item description.",
     image: "~/images/chefscollection.jpg",
     selected: false 
},
];

This is my template code:

<StackLayout class="topbuttons">
<GridLayout columns="*,*" horizontalAlignment="left" verticalAlignment="top">
    <Button class="btn btn-primary topbutton" text="Next" col="1" (tap)="onTap()"></Button>
</GridLayout>

more

<GridLayout tkExampleTitle tkToggleNavButton  class="topgrid" loaded="loaded" >
<RadListView [items]="dataItems" >
    <ng-template tkListItemTemplate let-item="item">
            <GridLayout class="garmentpick">
                <Image [src]="item.image" (tap)="toggleCheck()" class="imageP" >
                 </Image>
                <CheckBox #CB1 checked="false" text="" ></CheckBox>
        </GridLayout>
    </ng-template>
    <ListViewGridLayout tkListViewLayout ios:itemHeight="200" spanCount="2"></ListViewGridLayout>
</RadListView>

typescript

export class Component implements OnInit {
@ViewChild("CB1") firstCheckBox: ElementRef;

toggleCheck() {
    console.log();
    this.firstCheckBox.nativeElement.toggle();
}
onTap() {
    const checkboxArray = new ObservableArray(this.items);
    this._dataItems.forEach((item) => {
       checkboxArray.push(this.firstCheckBox.nativeElement.text);
    });        
}
}

I want to save the clicked items into an array. I created an array, I am pushing the clicked items to the array in the ontap of a submit button, but using Array.push(item.id) only pushes just one item, or repeats it in that array. is there a way I can do this, I'm thinking about data-forms




Aucun commentaire:

Enregistrer un commentaire