我正在使用Kotlin为Firebase云功能生成Javascript代码.
我想调用update方法,将一些值作为参数传递.在Kotlin中,我必须传递一个Map作为update()的参数:
val map = mutableMapOf<String,Int>() //also tried with a Hashmap: same result
//generate some values
for(i in 0 until 3){
map.put("key$i", i)
}
console.log(map.keys.toList().toString()) //log map keys
console.log(map.values.toList().toString()) //log map values
ref.child("values").update(map)
Run Code Online (Sandbox Code Playgroud)
Kotlin生成javascript代码:
var LinkedHashMap_init = Kotlin.kotlin.collections.LinkedHashMap_init_q3lmfv$;
function main$lambda(event){
var map = LinkedHashMap_init();
for (var i = 0; i < 3; i++) {
map.put_xwzc9p$('key' + i, i);
}
console.log(toList(map.keys).toString());
console.log(toList(map.values).toString());
ref.child('values').update(map);
}
Run Code Online (Sandbox Code Playgroud)
在我的Firebase控制台中,这是2个日志的结果.它似乎表明地图是正确的:
[key0, key1, key2]
[0, 1, 2]
Run Code Online (Sandbox Code Playgroud)
但是update()不起作用:函数日志显示该消息:
Error: Reference.update failed: First argument contains an …Run Code Online (Sandbox Code Playgroud)