mesqueeb mesqueeb - 3 months ago 12
JSON Question

Add a value to each line of a json string in the vuejs tree of components

I have a Vue component that first generates an empty list like so:

data: function(){
return {
list: [],
newThing: {
body: '',

I fill this list with json data I get through ajax in the component methods like so:

//ajax call
this.list = data.json();

I get an array with a bunch of objects as JSON like so:

[{"id":1,"body":"test body"},{"id":2,"body":"blablablabla"}]

Now my question is:

I want to add one additional value to each of these values! Like so:

[{"id":1,"body":"test body", "editMode":false},{"id":2,"body":"blablablabla","editMode":false}]

So that I can work in functionality into my task app.
Does anyone have any idea how to best do this?


Is this what you're looking for?

this.list.forEach(function (obj) {
  obj.editMode = false;