vue.js - Vue.js:如何更新对象数组?
问题描述
我正在尝试更新 Vue.js 中的对象数组。当尝试更新我的位置的值时,我正在努力更新数组中的对象。
当我注销对象时,我得到了这个:
console.log(this.location) // {…}
console.log(this.location.additionalProperties); // [{…}, __ob__: Observer]
console.log(this.location.additionalProperties.integrations); // undefined
我的additionalProperties
对象如下所示:
"additionalProperties": [
{
"integrations": [
{
"foo": {
"locationId": 123,
"example": "bar",
...
}
}
]
}
],
我将我的location
作为这样的道具传递:
location: {
type: Object,
required: true,
default: () => ({}),
},
我知道我得到了正确传递的位置。我相信这是我正在努力解决的语法问题。我正在尝试将我的foo
对象设置为如下所示:
this.location.additionalProperties.integrations.foo = {
locationId: 456,
example: "testing",
somethingElse: "anotherValue"
}
使用上面的,我会得到一个版本的cannot set foo of undefined
. 如何更新additionalProperties
数组中的对象?
感谢您的任何建议!
解决方案
AdditionalProperties 是一个数组
"additionalProperties": [
{
"integrations": [
{
"foo": {
"locationId": 123,
"example": "bar",
...
}
}
]
}
],
this.location.additionalProperties[0].integrations.foo = ...
推荐阅读
- python - 尝试在 python 中读取 csv 文件并创建单独的表
- java - 二进制到十进制计算器 InputMismatchException
- python - 循环中的发电机组被覆盖
- c - 将字符串与链表数据元素进行比较时,strcmp 不会返回 0
- node.js - 如何解决 Node.js 错误:找不到模块?
- java - JDK 11 Spring Boot 2 .TypeNotPresentException:类型 javax.servlet.Filter 不存在
- javascript - 为什么graphql查询在反应中不起作用?
- tensorflow - 如何在 keras 模型的自定义损失函数中使用 tensorflow.distributions
- assembly - 如何在'中结束字符串
'? - angular - 如何发布到后端服务器