首页 > 解决方案 > 绑定复选框不适用于我的方法 - Angular

问题描述

首先感谢您的帮助

我正在尝试为绑定复选框操作构建一个逻辑,它将获得一个对象数组(已经内置在我的 model.ts

export class Trip {

     constructor(
    
    
        infoTa: string,
        noContent: string,
        select: false,
        id: number,
        idTrasferta: string,
        idUtente: string,
        dataInizio: string,
        dataFine: string,

在创建我的 html 之后

 <th scope=^row>
    <input
    class="form-check-input"
    type="checkbox"
    style=margin-left:120px
    [value]="trip.id"
    [checked]="trip.select"
    (change)="selectTrip($event)">
   </th>

还有我在trips.component上的方法:

export class TripsComponent implements OnInit, RouterModule {

  checkedtrips: Trip

  selectTrip($event) {
    const id = $event.target.value;
    const isChecked = $event.target.checked;
    console.log(id, isChecked);

    this.checkedtrips = this.selectTrip.map((d)=> {
      if(d.id == id) {
      d.select = isChecked;
      return d;
      }
    })
  }

我的地图操作员对此抱怨

类型 '($event: any) => void'.ts(2339) 上不存在属性 'map'

问题是:如何使用我的对象数组来执行此操作并将用户选择的数组导出到另一个组件?

干杯

标签: jsonangulartypescript

解决方案


推荐阅读