当我用闪电记录表单更新一个帐户记录时,我一直在尝试重新修改一个表。我试着用我在这里发现的类似的问题来寻找解决方案,但我仍然无法做到这一点。在这种情况下,我硬编码了recordId的帐户,名字'Gonzalo‘显示在预览下面的所有代码。因此,想要的结果是更新帐户名称或任何字段,并在表中看到即时结果。这是我的密码:
@AuraEnabled(cacheable=true)
public static List<Account> getCuentas() {
return [SELECT id, Name, Phone FROM Account LIMIT 5];
} <lightning-record-form
object-api-name="Account"
record-id="0015e00000F2JoWAAV"
fields={fields}
onsubmit={handleSubmit}
>
</lightning-record-form><lightning-datatable
key-field="pk"
data={cuentas}
columns={columnas}
onrowselection={action}
hide-checkbox-column
onrowaction={handleRow}
default-sort-direction={defaultSortDirection}
sorted-direction={sortDirection}
sorted-by={sortedBy}
onsort={onHandleSort}
>
</lightning-datatable>***Imports***
import { refreshApex } from '@salesforce/apex';
import NAME from '@salesforce/schema/Account.Name';
import PHONE from '@salesforce/schema/Account.Phone';
import getCuentas from '@salesforce/apex/ProbandoJSON.getCuentas';
import { LightningElement, api, wire, track } from 'lwc';
***Vars for the form fields***
fields = [NAME, PHONE];
***Columns***
columnas = [
{
label: 'View',
type: 'button',
initialWidth: 75,
typeAttributes: {
label: {
fieldName: 'Boton'
},
title: 'Preview',
alternativeText: 'View',
variant: 'border-filled'
}
},
{
label: 'Name',
fieldName: 'Name',
sortable: true
},
{
label: 'Phone',
fieldName: 'Phone'
}
];
***Accounts***
@track cuentas = [];
_wiredResult;
@wire(getCuentas)
wireCuentas(result) {
this._wiredResult = result;
if(result.data) {
console.log('cuentas');
console.log(result.data);
for(var i in result.data) {
let obj = {};
obj.Id = result.data[i].Id;
obj.Name = result.data[i].Name;
obj.Phone = result.data[i].Phone;
obj.Boton = parseInt(i) + 1;
this.cuentas = [...this.cuentas, obj];
}
console.log('cuentas de nuevo');
console.log(this.cuentas);
} else if(result.error) {
console.log('error cuentas');
console.log(result.error);
}
}
***Submit handler for the Save button in the form***
handleSubmit(event) {
console.log('saving...')
return refreshApex(this._wiredResult);
}组件预览:
发布于 2021-08-18 07:10:59
看来是缓存问题。
我们可以通过以下几种方法解决这一问题:
您需要删除(cacheable=true),然后必须在每个表单更新时或在加载初始数据时紧急调用each方法。
您需要在顶点方法中接收一个额外的参数作为整数,然后在lwc中只需创建一个用0初始化它的变量,并在每次更新增量上增加1。
然后使用相同的var通过连线或命令式调用调用顶点方法。
https://stackoverflow.com/questions/68820595
复制相似问题