首页 > 解决方案 > 从Angular中的数组获取数据拼接

问题描述

在这里,我试图从我的复选框值中获取值,并且我正在尝试无法拼接的唯一类型模板中的数据。

这是我的html代码

 <div class="custom-control custom-checkbox" *ngFor="let data of Data; let i = index">
            <input class="custom-control-input" type="checkbox" (click)="SelectedTemplates(check, $event,i)" [checked]="checked" [value]="data.id" id="{{data.appName}}">
              <label class="custom-control-label" for="{{data.appName}}">{{data.templateName}} | {{data.appName}} |
                  {{data.docName}}</label>
          </div>

这是我的 Typescript 函数在拼接时无法获取值

SelectedTemplates(check, event, index) {
if (event.target.checked === true) {
  this.checkedItem = true;
  this.NewArry.push({'partnerId': this.PartnerID, 'templateId': this.Data[index].id});
} else if (event.target.checked === false) {
  for (let i = 0; i < this.NewArry.length; i++) {
    this.checkedItem = false;
    if (this.Data[index].id === this.NewArry[i]) {
      console.log(this.NewArry[i].id);
      this.NewArry.splice(i, 1);
    }
  }
}
   this.AreaArr = this.NewArry;
}

标签: angulartypescript

解决方案


只需将此代码添加到您的 else if

this.NewArry.splice(index, 1);

推荐阅读