[Vuejs]-Add a value to each line of a json string in the vuejs tree of components

0๐Ÿ‘

โœ…

Is this what youโ€™re looking for?

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

0๐Ÿ‘

this.list = data.json();
for (var i=0;i<this.list.length;i++){
this.list[i].editMode=false;
}

0๐Ÿ‘

this.list.forEach(o => o.editMode = false)

But only if you donโ€™t care about them being reactive. Otherwise you should use Vue.set

0๐Ÿ‘

Put your array in an variable and then iterate that variable and add accordingly.

<script>
var xyz =  [{"id":1,"body":"test body"},{"id":2,"body":"blablablabla"}];
$.each(xyz,function(i,data){
data['editMode'] = false;
})
</script>

Put this code Along with jquery library or you can write for loop in javascrpt you will get your desired output

-1๐Ÿ‘

After the ajax call, it sounds like a simple for loop should work:

for(var i = this.list.length; i--;){
this.list[i].editMode=false;
}

Leave a comment