Javascript 使用API端提供的id预选离子复选框

Javascript 使用API端提供的id预选离子复选框,javascript,angular,api,ionic-framework,ionic5,Javascript,Angular,Api,Ionic Framework,Ionic5,我经历了许多解决方案 我的爱奥尼亚应用程序中有一个复选框。我正在使用此应用程序中的反应。我调用一个api来获取复选框的数据列表- "Result": [ { "Subject_Id": 1 } ] 在这里,我从api端选择了一个主题id 我分享我的代码- //ts getSchemeDetail() { this.api .post( this.api.url + "GetS

我经历了许多解决方案

我的爱奥尼亚应用程序中有一个复选框。我正在使用此应用程序中的反应。我调用一个api来获取复选框的数据列表-

 "Result": [
    {
        "Subject_Id": 1
    }
]
在这里,我从api端选择了一个主题id

我分享我的代码-

//ts
getSchemeDetail() {
    this.api
      .post(
        this.api.url + "GetStudentList",
        { StudentId: this.Student.StudentId },
        false
      )
      .then((data: any) => {
     
          this.studentForm.patchValue({ 
          sID: data.sub_Id
          });
        }
        setTimeout(() => {
          this.getStudentList();
        }, 1000);
      })
      .catch((error: any) => {
        this.common.dismissLoading();
      });
  }
  
   getStudentList() {
    this.api
      .post3(
        "subjectid",
        {
          StudentId: this.studentId,
        }, true )
      .then((data: any) => {
        this.SubList = data.Result;
        setTimeout(() => {
            this.studentForm.patchValue({ sID: this.sid });
            if (this.vid == this.SubList) {
              this.isChecked = true;
            } else {
              this.isChecked = false;
            }
          
        }, 100);
      })
      .catch((error) => {
        console.log("State Error => ", error);
      });
  }
我的HTML代码是

   //Html code
 <div *ngFor="let s of SubList">
           <ion-checkbox color="primary" type="checkbox" formControlName="sID" [(ngModel)]="s.isChecked" >
</div>
//Html代码
我正在选中所有复选框


那么,我如何才能从API端只显示选中的复选框,而您使用
this.studentForm.patchValue({sub:data.sub_Id})修补值呢在这里,您有两个不同的formControlName。
sub
sID
这两个都是未知的other@GaurangDhorda我用另一个例子解释了这是一个错误,现在我纠正了这个错误。你能共享
子列表
对象的数据吗?并且
[(ngModel)]=“s”被选中了吗“
这个
s
从哪里来?@GaurangDhorda{“sub_Id”:1,“SubName”:'eng,},s来自子列表。您的api为所有复选框Id提供
checked:true