Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

ionic framework - Issues with setting ion-checkbox value using arrays in Angular

I have been trying to figure out the best way to set a series of ion-checkbox's using an array that is fed into my app through an API.

Right now, my app receives some data that looks like this:

{
    "data": {
        "tags": [
            55, 46, 193, 1002
        ]
    }
}

I am then using a series of ion-checkbox's to display whether or not that tag is selected for a certain item, like this:

<ion-item lines="full">
   <ion-label position="fixed" class="ion-text-wrap">Blue</ion-label>
   <ion-checkbox slot="end" [(ngModel)]="item.tags" [value]="55" [checked]="item.tags.indexOf(55) > 0"></ion-checkbox>
</ion-item>

I am getting an error with the indexOf function, saying it's not a function.

Is there a better way to try and create a list of items and see if the value is in an array, and then show the checkbox as checked if it is?

question from:https://stackoverflow.com/questions/65873294/issues-with-setting-ion-checkbox-value-using-arrays-in-angular

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.7k users

...