【发布时间】:2017-08-17 09:36:37
【问题描述】:
我有一个这样的组列表:
{"data":
[
{"id":"221","title":"group1"},
{"id":"18","title":"Group2"},
{"id":"306","title":"Group3"},
{"id":"19","title":"Group4"}
]
}
在模板中,我循环遍历上述对象的所有组并将它们显示如下:
<ion-select [(ngModel)]="user.group" multiple="true" name="group">
<ion-option *ngFor="let group of groups" [value]="group.id" [selected]="ifIsInGroup(group.id)">
{{ group.title }}
</ion-option>
</ion-select>
在我的页面类中,我有一个对象,其中包含用户已分配到的组:
{ "mygroups":[{"title":"Group2","id":"18"}]}选择或不选择选项的功能:
ifIsInGroup(itemID){
if(what to do here?){
return true
} else {
return false;
}
}
如何检查数据(所有组)列表中是否存在 mygroups 项?并返回 true sow 选项被选中?
【问题讨论】: