我有一个卡列表,并从这种结构的服务器获取json:
object1 : {
prop1 : ''
listOfObjects : []
}
所以object1与listOfObjects中的对象有很多对多的关系。而且我只获得与我的主要视图关系链接的对象。
要查看此链接对象,我使用离子4的离子选择组件。我需要勾选所有对象中仅选择的链接对象。例如。
Full list of objects
obj1
obj2
obj3
obj4
链接到主模型的对象
在离子选择中,它就像那样
我怎么能得到它???
projectService.projectsList >>从服务器sprintService.selectedSprint.projects获取所有项目>>链接项目到sprint
如果离子选择不可能,请给我任何替代方案...谢谢大家。
<ion-select #projects ngModel name="projects" [(ngModel)]="sprintService.selectedSprint.projects"
multiple="true">
<ion-select-option *ngFor="let project of projectService.projectsList" [value]="project">
{{project.name}}
</ion-select-option>
</ion-select>
my model
export class Sprint{
id : number;
name : string;
description : string;
startDate : string;
endDate : string;
priority : number;
projects : Project[]
}
export class Project{
id : number;
name : string;
description : string;
startDate : string;
endDate : string;
}
尝试添加比较功能,这样就可以确定选择了哪些项目。像这样的东西。
<ion-select [(ngModel)]="projects" multiple="true" [compareWith]="compareObject">
<ion-select-option *ngFor="let p of sprintService.selectedSprint.projects" [value]="p">{{p.name}}</ion-select-option>
</ion-select>
compareObject(a: any, b: any) {
return a.id === b.id;
}