gpt4 book ai didi

kotlin - 使用动态属性名称将属性分配给javascript对象

转载 作者:行者123 更新时间:2023-12-02 12:43:49 25 4
gpt4 key购买 nike

我想做这样的事情,但我不知道,我不能使用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
}
}

最佳答案

您可以像使用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;
}
}

关于kotlin - 使用动态属性名称将属性分配给javascript对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44841408/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com