Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.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
Angular 取消编辑ngx数据表中的行并返回到以前的数据_Angular_Angular Material - Fatal编程技术网

Angular 取消编辑ngx数据表中的行并返回到以前的数据

Angular 取消编辑ngx数据表中的行并返回到以前的数据,angular,angular-material,Angular,Angular Material,我正在运行此示例,并试图通过单击“取消x”按钮并使用以前的数据重置所选行来取消编辑行。我将数据保存到localstorage,但在取消编辑后得到空数据。有帮助吗 这是取消操作的代码: cancel(row, rowIndex) { this.isEditable[rowIndex] = !this.isEditable[rowIndex]; // this.rows = this.data; this.rows = [...[]]; this.rows.push

我正在运行此示例,并试图通过单击“取消x”按钮并使用以前的数据重置所选行来取消编辑行。我将数据保存到localstorage,但在取消编辑后得到空数据。有帮助吗

这是取消操作的代码:

cancel(row, rowIndex) {
    this.isEditable[rowIndex] = !this.isEditable[rowIndex];
    // this.rows = this.data;
    this.rows = [...[]];

    this.rows.push(JSON.parse(localStorage.getItem("data")));

    // this.rows.forEach(row => {
    //   let testArr = [];
    //   row.nota.forEach(nota => {
    //     testArr.push(nota.test);
    //   });
    //   row.selected = testArr;
    // });
    this.rows = [...this.rows];
    // this.rows = [...this.rows];
    console.log("Row canceled: " + rowIndex);
  }

您正在使用
行。推送(…)
并向其传递数组,这不起作用

替换

this.rows = [...[]];
this.rows.push(JSON.parse(localStorage.getItem("data")));

那会让你走的

this.rows = JSON.parse(localStorage.getItem("data"));