如果我给它一个参数,我会不断从我的承诺的响应中收到错误。我不知道是否应该将“columndefinitions”参数传递给 apex 方法。我附上了图片以提供帮助。 PS:如果我省略参数,它会返回一个空数组,但不会出现错误。
想法:我是否错误地传递了参数?我的列定义格式是否错误?是语法问题吗?
JS 文件
//before render, call an apex method query...
connectedCallback() {
getValidFields(this.getColumnDefinitions)
.then((response) => {
console.log('getvalidfields', response)
}).catch((error) => {
console.error(error);
});
getColumnDefinitions() {
return [
{
object: "Contact", apiName: "Name", label: 'Name', fieldName: 'contactURL', type: 'url', iconName: 'standard:contact', sortable: 'true',
filterable: true, typeAttributes: { label: { fieldName: 'contactName' }, target: '_self', tooltip: 'Click to view Contact details' }
},
{ object: "Contact", apiName: "Phone", label: 'Phone', fieldName: 'contactPhone', type: 'phone', sortable: false, filterable: true },
{ object: "Contact", apiName: "Email", label: 'Email', fieldName: 'contactEmail', type: 'email', sortable: false, filterable: true },
{ object: "Contact", apiName: "MailingAddress", label: "Address", fieldName: 'contactAddress', type: 'text', filterable: false },
{ object: "Contact", apiName: "Group_Rank__c", label: 'Group Rank', fieldName: 'contactGroupRank', type: 'text', sortable: true, filterable: true },
{ object: "Contact", apiName: "Role_Function__c", label: 'Role Function', fieldName: 'contactRoleFunction', type: 'text', sortable: true, filterable: false },
{ object: "ContactTerritoryRelationship__c", apiName: "TerritoryManagerRole__c", label: 'Territory Manager Role', fieldName: 'contactTerritoryRole', type: 'text', sortable: true, filterable: false },
{
object: "DistributionTerritory__c", apiName: "Name", label: 'Distribution Territory', fieldName: 'contactTerritoryURL', type: 'url', sortable: true, filterable: true, iconName: 'custom:custom78',
typeAttributes: { label: { fieldName: 'contactTerritoryName' }, target: '_self', tooltip: 'Click to view Distribution Territory details' }
},
{ object: "ContactTerritoryRelationship__c", apiName: "DistributionTerritory__c", type: "action", filterable: false, typeAttributes: { rowActions: this.rowActions } }
];
}
控制器.CLS
@AuraEnabled
public static List<Map<String, Object>> getValidFields(List<Map<String, Object>> columnDefinitions) {
for (Integer i = 0; i < columnDefinitions.size(); i++) {
Map<String, Object> column = columnDefinitions.get(i);
if (column.containsKey('object') && !userHasAccess((String) column.get('object'), (String) column.get('apiName'))) {
columnDefinitions.remove(i);
}
}
return columnDefinitions;
}
如果从 LWC 命令式调用 apex 操作,则应该将参数作为对象传递。对象属性的名称应类似于您的 Apex 方法参数。
在你的情况下应该是:
getValidFields({ columnDefinitions: this.getColumnDefinitions()} ).then(...)
请参阅以下链接了解更多详细信息:https://developer.salesforce.com/docs/platform/lwc/guide/apex-call-imperative.html#call-an-apex-method-with-parameters