带有peditablecolumn的p-table正在替换第二个桌子的价值
我有两个桌子(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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,您要做的就是为变量
listaCoberturasEmpregados
和listaCoberturasSocios
分配相同的内容 (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 variableslistaCoberturasEmpregados
andlistaCoberturasSocios
. 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