2

I am trying to update an array of objects in Vue.js. When trying to update the values of my location I am struggling to update the objects within an array.

When I log the objects out, I get this:

console.log(this.location) // {…}

console.log(this.location.additionalProperties);  // [{…}, __ob__: Observer]

console.log(this.location.additionalProperties.integrations);  // undefined

My additionalProperties object looks like this:

"additionalProperties": [
    {
      "integrations": [
        {
           "foo": {
               "locationId": 123,
               "example": "bar",
               ...
           }
        }
      ]
    }
],

I am passing in my location as a props like this:

location: {
    type: Object,
    required: true,
    default: () => ({}),
},

I know I am getting the location passed in correctly. I believe it is a syntax issue I am struggling with. I am trying to set my foo object to be something like this:

this.location.additionalProperties.integrations.foo = {
   locationId: 456,
   example: "testing",
   somethingElse: "anotherValue"
}

Using the above, I'll get a version of cannot set foo of undefined. How can I update the object within the additionalProperties array?

Thank you for any suggestions!

1 Answer 1

2

additionalProperties is an array

"additionalProperties": [
    {
      "integrations": [
        {
           "foo": {
               "locationId": 123,
               "example": "bar",
               ...
           }
        }
      ]
    }
],

this.location.additionalProperties[0].integrations.foo = ...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.