简体   繁体   English

如何将Javascript映射作为参数从闪电组件发送到Apex服务器控制器?

[英]How to send Javascript map as a parameter from lightning component to Apex server controller?

I have a salesforce lightning component which enqueues server side action. 我有一个Salesforce Lightning组件,可以使服务器端采取行动。 To that action I need to pass a map as one of the parameters, but it looks like it takes memory address of the object instead. 为此,我需要将映射作为参数之一传递,但是看起来它却改为使用对象的内存地址。

The client side code that creates the map and calls the server side action: 创建地图并调用服务器端操作的客户端代码:

var action = cmp.get("c.save");
var mapToSend = new Map()
for (var key of valueMap.keys()) {
    mapToSend.set(key, valueMap.get(key))
}
action.setParams({
    "name": cmp.get("v.name"),
    "params": mapToSend
});

In the controller then: 然后在控制器中:

 public static Boolean save(String name, Map<String, Object> params) {

log of the javascript shows nice Map with all the correct fields, but salesforce system log shows just javascript的日志显示具有所有正确字段的精美Map ,但是salesforce系统日志仅显示

14:55:16.0 (3172304)|VARIABLE_SCOPE_BEGIN|[41]|name|String|false|false
14:55:16.0 (3188041)|VARIABLE_ASSIGNMENT|[41]|name|"Account"
14:55:16.0 (3191758)|VARIABLE_SCOPE_BEGIN|[41]|params|Map<String,ANY>|true|false
14:55:16.0 (3204719)|VARIABLE_ASSIGNMENT|[41]|params|{}|0x30d2397a

Any Idea why? 知道为什么吗? What those |false|false and |true|false mean in the logs? 日志中的|false|false|true|false是什么意思?

The problem is with understanding the javascript data structures. 问题在于了解javascript数据结构。 The correct result is achieved by calling the apex controller with data prepared as 正确的结果是通过调用apex控制器获得的,数据准备如下:

var mapToSend = {}
for (var key of valueMap.keys()) {
    mapToSend[key] = valueMap.get(key);
}
action.setParams({
    "name": cmp.get("v.name"),
    "params": mapToSend
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在没有顶点的闪电 web 组件上创建任务仅 javascript controller? - Create a task on a lightning web component without apex only javascript controller? 如何在laravel 5中将参数从javascript发送到控制器? - How to send parameter from javascript to controller in laravel 5? 在JavaScript Home组件中定义Apex控制器 - Define Apex controller in javascript home component Salesforce Aura 组件,如何将值从闪电:选择传递到 onchange 控制器? - Salesforce Aura component, how to pass value from lightning:select to onchange controller? 控制器未从闪电组件初始化处理程序接收对象 - Controller not receiving Object from Lightning Component Init Handler 有没有办法从闪电 Web 组件(LWC)中的 JS 将多个(和不同的)参数传递给 Apex Controller class? - Is there a way to pass multiple (and different) parameters to an Apex Controller class from JS in Lightning Web Components (LWC)? 将Html作为参数从javascript发送到asp.net mvc控制器 - Send Html as parameter from javascript to asp.net mvc controller Salesforce Lightning Component不会通过Apex调用更新记录,从而冻结 - Salesforce Lightning Component will not update records via Apex call, freezes 如何将参数从JavaScript传递到Codeigniter中的控制器? - How to pass parameter from javascript to controller in codeigniter? Lightning 组件,在控制器中检索查找记录值 - Lightning Component, retrieving lookup record values in controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM