I am facing an issue with tracking changes in an array before and after it is reordered. I have two variables, originalOrder
and rulesetOrder
. My component is connected to rulesetOrder
, so when I move an item, the array updates according to its new index. Every time a reorder happens, I compare originalOrder
with rulesetOrder
. After all comparisons are done, I update originalOrder
with the latest rulesetOrder
.
The problem arises when I reorder for the second time. It seems like originalOrder
automatically syncs with rulesetOrder
, making it hard to spot any differences between the arrays.
Below is my code snippet. Can anyone assist me in ensuring that originalOrder
always reflects the previous state of the array whenever the event is triggered again?
OnReorder()
{
console.log("Start: " + JSON.stringify(this.originalOrder));
console.log("New Order:" + JSON.stringify(this.rulesetOrder));
this.originalOrder = this.rulesetOrder;
}
Does setting originalOrder
equal to rulesetOrder
create a binding between them? How can I prevent them from syncing up automatically?
First time:
Start: ["ae74e7fd-a772-4fa2-b2cb-19c7c0bc611f", "1caf3416-9853-49eb-8bda-c3b9017a204a", "9e5fe94d-6c0e-4b85-85f4-38a074badfeb"]
New Order:["1caf3416-9853-49eb-8bda-c3b9017a204a", "ae74e7fd-a772-4fa2-b2cb-19c7c0bc611f","9e5fe94d-6c0e-4b85-85f4-38a074badfeb"]
2nd time:
Start: ["ae74e7fd-a772-4fa2-b2cb-19c7c0bc611f","1caf3416-9853-49eb-8bda-c3b9017a204a","9e5fe94d-6c0e-4b85-85f4-38a074badfeb"]
New Order:["ae74e7fd-a772-4fa2-b2cb-19c7c0bc611f","1caf3416-9853-49eb-8bda-c3b9017a204a","9e5fe94d-6c0e-4b85-85f4-38a074badfeb"]