Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k 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 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...