有人可以帮我在我的 lwc 闪电数据表中显示相关的 Account.name 吗?
这是我的js文件
import { LightningElement, wire } from 'lwc';
import ID_FIELD from '@salesforce/schema/Opportunity.Id';
import ACCOUNT_NAME_FIELD from '@salesforce/schema/Account.Name';
import STAGE_FIELD from
'@salesforce/schema/Opportunity.StageName';
import getAccounts from
'@salesforce/apex/relatedNameQuery.getAccounts';
const COLUMNS = [
{ label: 'ID', fieldName: ID_FIELD.fieldApiName, type: 'text' },
{ label: 'Account Name', fieldName:
ACCOUNT_NAME_FIELD.fieldApiName, type: 'text' },
{ label: 'Stage', fieldName: STAGE_FIELD.fieldApiName, type:
'text' }
];
export default class AccountList extends LightningElement {
columns = COLUMNS;
@wire(getAccounts)
accounts;
}
这是我的 cls 文件
public with sharing class relatedNameQuery {
@AuraEnabled(cacheable=true)
public static List<Opportunity> getAccounts() {
return [
select Id, Account.name, StageName
from Opportunity
where StageName = 'Closed Won'
];
}
}
这是我的html文件
<template>
<lightning-card>
<template if:true={accounts.data}>
<lightning-datatable
key-field="Id"
data={accounts.data}
columns={columns}
>
</lightning-datatable>
</template>
</lightning-card>
</template>
我知道选项是使用包装器或展平数据,但我被卡住了