如何在 ion-select 组件的完整列表中查看 selected 项目?

How to view selected items in full list of ion-select component?

我有一个卡片列表,并从服务器中获取 json 这样的结构:

object1 : {
  prop1 : ''
  listOfObjects : []
}

所以 object1 与 listOfObjects 中的对象具有多对多关系。 而且我只得到与我的主要视图对象相关的对象。

要查看此链接对象,我使用 ionic 4 的 ion-select 组件。 我需要勾选为 selected 仅来自所有对象的链接对象。例如

Full list of objects
obj1
obj2
obj3
obj4

链接到主模型的对象

在 ion-select 中会是这样

我怎样才能得到它???

projectService.projectsList>> 从服务器获取所有项目 sprintService.selectedSprint.projects >> 将项目链接到 sprint

如果 ion-select 无法解决这个问题,请给我任何替代方案...谢谢大家。

<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;
}