我想做类似的事情,但我不知道,我不能使用js()来插入任何动态数据,因为js()只接受常量字符串参数(或者有办法那样做?)
val doc: dynamic = Any()
doc._id = name
data.forEach {
it.forEach { entry ->
// need to set property of the doc using entry.key as the property name with entry.value
}
}
答案 0 :(得分:3)
您可以像使用javascript括号访问表示法一样使用indexed access,例如:
val doc: dynamic = Any()
doc._id = name
data.forEach {
it.forEach { entry ->
// v--- kotlin process the brackets []= as a set operator
doc[entry.key] = entry.value;
}
}