带有peditablecolumn的p-table正在替换第二个桌子的价值

发布于 2025-01-20 12:36:50 字数 2741 浏览 5 评论 0 原文

我有两个桌子(p-table),带有编辑行。但是,当我在第一个表中更新行值时,它也会更新第二个表。 我如何将这些桌子行设置为唯一?

- >表组件:

<p-table [value]="coberturas" dataKey="id" editMode="row">
<ng-template pTemplate="header">
  <tr>
    <th class="width-20rem">
      {{ t("coberturas.dadosCobertura.tabela.cobertura") }}
    </th>
    <th>{{ t("layout.topicosComuns.capitalIndividual") }}</th>
    <th>{{ t("coberturas.dadosCobertura.tabela.vlrMin") }}</th>
    <th>{{ t("coberturas.dadosCobertura.tabela.vlrMax") }}</th>
    <th>{{ t("layout.topicosComuns.capitalGlobal") }}</th>
  </tr>
</ng-template>
<ng-template pTemplate="body" let-cobertura>
  <tr>
    <td>
      {{ cobertura.nomeMatrizCobertura }}
    </td>
    <td pEditableColumn>
      <p-cellEditor>
        <ng-template pTemplate="input">
          <p-dropdown
            *ngIf="cobertura.codigoMatrizCobertura == 819"
            [(ngModel)]="auxilioFuneral"
            [options]="auxiliosFunerais"
            optionLabel="valor"
            [style]="{ width: '100%' }"
          ></p-dropdown>
          <input
            *ngIf="cobertura.codigoMatrizCobertura != 819"
            [(ngModel)]="cobertura.capitalIndividual"
            pInputText
            type="text"
            required
          />
        </ng-template>
        <ng-template pTemplate="output">
          {{ cobertura.capitalIndividual }}
        </ng-template>
      </p-cellEditor>
    </td>
    <td pEditableColumn>
      <p-cellEditor>
        <ng-template pTemplate="input">
          {{ cobertura.valorMatrizMinimoImportancia | realPipe }}
        </ng-template>
        <ng-template pTemplate="output">
          {{ cobertura.valorMatrizMinimoImportancia | realPipe }}
        </ng-template>
      </p-cellEditor>
    </td>
    <td pEditableColumn>
      <p-cellEditor>
        <ng-template pTemplate="input">
          {{ cobertura.valorMatrizMaximoImportancia | realPipe }}
        </ng-template>
        <ng-template pTemplate="output">
          {{ cobertura.valorMatrizMaximoImportancia | realPipe }}
        </ng-template>
      </p-cellEditor>
    </td>
    <td pEditableColumn></td>
  </tr>
</ng-template>

我正在设置两个具有两个不同值的表

    <als-tabela-cotacao
  *ngIf="!tabelaSocio"
  [coberturas]="listaCoberturasEmpregados"
></als-tabela-cotacao>

<als-tabela-cotacao
  *ngIf="tabelaSocio"
  [coberturas]="listaCoberturasSocios"
></als-tabela-cotacao>

I have two tables (p-table) with editing rows. But, when I update the row value in the first table, it updates the second table too.
How could I set this tables rows as unique?

-> Table component:

<p-table [value]="coberturas" dataKey="id" editMode="row">
<ng-template pTemplate="header">
  <tr>
    <th class="width-20rem">
      {{ t("coberturas.dadosCobertura.tabela.cobertura") }}
    </th>
    <th>{{ t("layout.topicosComuns.capitalIndividual") }}</th>
    <th>{{ t("coberturas.dadosCobertura.tabela.vlrMin") }}</th>
    <th>{{ t("coberturas.dadosCobertura.tabela.vlrMax") }}</th>
    <th>{{ t("layout.topicosComuns.capitalGlobal") }}</th>
  </tr>
</ng-template>
<ng-template pTemplate="body" let-cobertura>
  <tr>
    <td>
      {{ cobertura.nomeMatrizCobertura }}
    </td>
    <td pEditableColumn>
      <p-cellEditor>
        <ng-template pTemplate="input">
          <p-dropdown
            *ngIf="cobertura.codigoMatrizCobertura == 819"
            [(ngModel)]="auxilioFuneral"
            [options]="auxiliosFunerais"
            optionLabel="valor"
            [style]="{ width: '100%' }"
          ></p-dropdown>
          <input
            *ngIf="cobertura.codigoMatrizCobertura != 819"
            [(ngModel)]="cobertura.capitalIndividual"
            pInputText
            type="text"
            required
          />
        </ng-template>
        <ng-template pTemplate="output">
          {{ cobertura.capitalIndividual }}
        </ng-template>
      </p-cellEditor>
    </td>
    <td pEditableColumn>
      <p-cellEditor>
        <ng-template pTemplate="input">
          {{ cobertura.valorMatrizMinimoImportancia | realPipe }}
        </ng-template>
        <ng-template pTemplate="output">
          {{ cobertura.valorMatrizMinimoImportancia | realPipe }}
        </ng-template>
      </p-cellEditor>
    </td>
    <td pEditableColumn>
      <p-cellEditor>
        <ng-template pTemplate="input">
          {{ cobertura.valorMatrizMaximoImportancia | realPipe }}
        </ng-template>
        <ng-template pTemplate="output">
          {{ cobertura.valorMatrizMaximoImportancia | realPipe }}
        </ng-template>
      </p-cellEditor>
    </td>
    <td pEditableColumn></td>
  </tr>
</ng-template>

I'm setting two tables with two different values, each 'als-tabela-cotacao' is the component above

    <als-tabela-cotacao
  *ngIf="!tabelaSocio"
  [coberturas]="listaCoberturasEmpregados"
></als-tabela-cotacao>

<als-tabela-cotacao
  *ngIf="tabelaSocio"
  [coberturas]="listaCoberturasSocios"
></als-tabela-cotacao>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

能否归途做我良人 2025-01-27 12:36:50

因此,您要做的就是为变量 listaCoberturasEmpregadoslistaCoberturasSocios 分配相同的内容 (res.data.listaOcorrenciaMatrizCobertura)。对于 javascript 来说它仍然是相同的,因为它引用相同的原始变量。我建议是使用析构运算符创建数组的副本 = this.listaCoberturasSocios = [...res.data.listaOcorrenciaMatrizCobertura]

在这里您可以检查一个工作示例如何做它,取消注释代码以查看正确的解决方案:

https://stackblitz.com/edit/angular- ivy-ih6bod?file=src%2Fapp%2Fapp.component.ts

So what you're doing is you're assigning same thing (res.data.listaOcorrenciaMatrizCobertura) to both variables listaCoberturasEmpregados and listaCoberturasSocios. For javascript it's still the same, since it's refers to the same original variable. What I'd recommend is to use a destruct operator to create a copy of the array = this.listaCoberturasSocios = [...res.data.listaOcorrenciaMatrizCobertura]

Here you can check a working example how to do it, uncomment the code to see proper solution:

https://stackblitz.com/edit/angular-ivy-ih6bod?file=src%2Fapp%2Fapp.component.ts

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文