Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/464.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从数组中重置值,单击按钮?_Javascript_Angular_Typescript_Tabulator - Fatal编程技术网

Javascript 如何从数组中重置值,单击按钮?

Javascript 如何从数组中重置值,单击按钮?,javascript,angular,typescript,tabulator,Javascript,Angular,Typescript,Tabulator,我正在使用制表器生成一个表。单击表格单元格时,我将单元格值推送到数组中,数组中每个项目的初始值为“0”。我想实现一个重置按钮,在单击重置按钮或窗口中的任何位置时,该按钮会将分配的值重置为“0” 组件。ts names = [{name: first, val: void 0},{name: second, val: void 0}] tabulatorColumnName = [{title: firstTitle, field: firstField, cellClick:

我正在使用制表器生成一个表。单击表格单元格时,我将单元格值推送到数组中,数组中每个项目的初始值为“0”。我想实现一个重置按钮,在单击重置按钮或窗口中的任何位置时,该按钮会将分配的值重置为“0”

组件。ts

 names = [{name: first, val: void 0},{name: second, val: void 0}]

 tabulatorColumnName = [{title: firstTitle, field: firstField, cellClick: 
                          this.getValue.bind(this)}
                        {title: secondTitle, field: secondField, 
                          cellClick:this.getValue.bind(this)}]
假设只有一行数据,下面的函数将第一个字段和第二个字段的数据推送到names[0].val和names[1].val

     getValue(e, row) {
          this.names[0].val = row.getData().firstField
          this.names[1].val = row.getData().secondField

     }
component.html

我想实现一个功能或按钮,当用户单击窗口中的任意位置或按钮时,该功能或按钮将清除[(ngmodel)]值

 <form (ngSubmit)="saveChild(sideToggleForm)" 
  #sideToggleForm="ngForm">
  <div *ngFor="let name of names">
    <div class="{{ name.type }}">
      <small>{{ name.label }}</small>
      <mat-form-field class="full-width" appearance="outline">
        <input
          name="{{ name.name }}"
          matInput
          [(ngModel)]="name.val"
        />
      </mat-form-field>
    </div>
  </div>
</form>

{{name.label}

在HTML中添加一个按钮

<button (click)="resetNameValues()">Reset</button>

在HTML中添加一个按钮

<button (click)="resetNameValues()">Reset</button>

我建议您创建数据的深度克隆,然后使用此克隆对象设置值。我建议您创建数据的深度克隆,然后使用此克隆对象设置值。