闪电数据表显示与联系人记录相关的信息。
我得到改变的字段,新的数据和行 ID,但不是记录 ID。
调试日志显示我回来一个空白的对象时,试图添加 recordId 按照Doc for editing multiple rows with Apex.
我搜索过的所有东西都让它看起来像是幕后的魔法,但我没有尝试过可以正确添加这个 recordId。我可以看到 'row' 有数据,但我得到一个空白或空的对象。
我错过了什么?
html 代码段
<template if:true={isContact}>
<lightning-datatable
key-field="id"
data={family}
columns={petColumns}
onsave={handleSave}
draft-values={draftValues}>
</lightning-datatable>
</template>
js 代码段
const COLS = [
{
label: 'Name',
fieldName: 'recordUrl',
type: 'url',
typeAttributes: {label: { fieldName: 'Name' },
target: '_blank'},
sortable: true
},
{ label: 'Birthday', fieldName: 'Birthday__c', editable: true, type: 'date-local' },
{ label: 'Type', fieldName: 'Type__c'},
{ label: 'Age', fieldName: 'Age__c', type: 'number', cellAttributes: { alignment: 'left' } }
];
async handleSave(event) {
const updatedFields = event.detail.draftValues;
console.log('updatedFields: ' + JSON.stringify(updatedFields))
// Prepare the record IDs for getRecordNotifyChange()
const notifyChangeIds = updatedFields.map(row => {
console.log('row: ' + JSON.stringify(row))
return { "recordId": row.Id } });
// now the object is blank
console.log('notifyChangeIds: ' + JSON.stringify(notifyChangeIds))
try {
// P edited fields to the updatePets Apex controller
const result = await updateRecord({data: updatedFields});
console.log(JSON.stringify("Apex update result: "+ result));
this.dispatchEvent(
new ShowToastEvent({
title: 'Success',
message: 'Record updated',
variant: 'success'
})
);
// Refresh LDS cache and wires
getRecordNotifyChange(notifyChangeIds);
// Display fresh data in the datatable
refreshApex(this.pets).then(() => {
// Clear all draft values in the datatable
this.draftValues = [];
});
} catch(error) {
showToast('Error updating or refreshing records', error.body.message, 'error', 'sticky')
}
}
也尝试了使用.slice()的方法,但同样的事情发生,我得到一个空白对象回来。
const recordInputs = event.detail.draftValues.slice().map(draft => {
const fields = Object.ign({}, draft);
return { fields };
});
调试显示:
updatedFields: [{"Birthday__c":"2001-06-14","id":"row-0"}]
myTest.js:1 row: {"Birthday__c":"2001-06-14","id":"row-0"}
myTest.js:1 notifyChangeIds: [{}]
谢谢
本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处
评论列表(86条)