0

我有一张表,它的值来自tablesValue.

<p-table [value]="tablesValue">

我需要支持“删除用户可以在桌面上进行的所有更改”。所以一开始我复制tablesValuetablesValueBackup. 当用户单击按钮时,我会显示一个对话框:

<p-confirmDialog header="Confirmation" icon="pi pi-exclamation-triangle"></p-confirmDialog>

在 ts 中,我这样做:

    click(){
     let tablesValue=this.tablesValue;
        let tablesValueBackup=this.tablesValueBackup;
        this.confirmationService.confirm({
          message: 'Delete all change',
          accept: () => {
            //the problem is here because the table is not update
            tablesValue= tablesValueBackup;
            console.log(tablesValue);
          }
        });
    }

为什么当我单击确认按钮中的接受按钮时,表格未在 UI 中更新,但在console.log其中打印正确的值?

4

1 回答 1

0

尝试这个!

你只是混淆了相同的变量名

click(){
let tablesValue=this.tablesValue;
    const tablesValueBackupLocal=JSON.parse(JSON.stringify(this.tablesValueBackup));
    this.confirmationService.confirm({
      message: 'Delete all change',
      accept: () => {
        //the problem is here because the table is not update
        this.tablesValue= tablesValueBackup;
        console.log(this.tablesValue);
      }
    });
}
于 2020-03-03T12:09:52.100 回答