javascript - 字符串插值格式在 Firestore 更新功能中不起作用
问题描述
我的目标是将我的type
道具传递给一个字符串:
db.collection("users").doc(user).collection("theme").doc(user).update({
`button.${type}`: e.target.value,
});
但是, `button.${type}`: e.target.value,
呈现错误Unexpected token (86:8)
有任何想法吗?
解决方案
传递字符串键以访问对象中的变量的正确方法是obj[stringKey]
:
{ [button[type]]: e.target.value }
你只需要确保它button[type]
不是未定义的,否则你的对象将是{ undefined: e.target.value }
推荐阅读
- powershell - 如果命令响应包含
- java - 如何替换java中字符串列表中整数的第一个实例?
- python - Python:同时使用 os.fork()、os.pipe() 和 subprocess.Popen 问题
- excel - 来自另一个工作表的 VBA IF 命令
- c# - 为什么将 2 个 .NET 框架类相互比较会导致 stackoverflow 异常?
- javascript - firebase.messaging:无法读取未定义的属性“getNotificationPermission_”
- javascript - 我如何在从表单获取用户输入的对象数组中设置状态
- tfs - Team Foundation Server 2018 API 构建定义错误
- java - 打印 kafka 流的内容时出现问题
- vb.net - VB 流阅读器无法正确读取