I have two data objects called items and itemsOrg
var vm = new Vue({
el: '#divVM',
mixins: [mix],
data: {
items: [],
itemsOrg:[],
// ....
},
When the page loads, I make an AJAX call to fetch data from MySQL table and assign it to items and itemsOrg object.
function getMustacheVariables()
{
$.ajax({
type: "POST",
url: "adminAjax.php",
data: {
actionID: 'GET_DATA',
},
dataType: "json",
success: function(data)
{
vm.items= data;
vm.itemsOrg = data;
}
// ...
However, when I update Vm.items, vm.itemsOrg is also automatically updated and don't know why these the two are linked. Here is a snapshot of console.log
vm.items[0]["key"]
"agent"
vm.itemsOrg[0]["key"]
"agent"
vm.items[0]["key"] = "new_key"
"new_key"
vm.itemsOrg[0]["key"]
"new_key"
vm.itemsOrg[0]["key"] = "updated_key"
"updated_key"
vm.items[0]["key"]
"updated_key"
Is there a reason that these two objects are linked? I even tried assigning vm.items to vm.itemsOrg using vm.items.slice() as well as push() but the two objects are always linked.
I appreciate any help.