I'm wrestling with what seems to be a straightforward issue, but for some reason I can't update the pos field value in the WorkSetTemplate object within an array.
Here's the code snippet:
export class WorkSetTemplate {
static alignPositionWithDisplay(coll: WorkSetTemplate[]): WorkSetTemplate[] {
for (let i = 0; i < coll.length; i++) {
coll[i].pos = i + 1;
}
return coll;
}
constructor(
public id?: number,
public nk?: string,
public pos?: number,
public name?: string,
public maintainerId?: number,
public airworthinessDirectiveIssueNumber?: string,
public workItemTemplates?: WorkItemTemplate[]
) {}
}
Let's say we begin with these sets:
https://i.sstatic.net/R2deq.png
Then, I execute the static method like this:
Sets = WorkSetTemplate.alignPositionWithDisplay(sets);
In theory, I anticipate seeing the same set arrangement, but with the pos values sequentially assigned as 1, 2, 3 (instead of 2, 1, 3).
However, no change actually occurs - the pos values remain as 2, 1, 3. Even though, if I use console.log inside the loop, I can see that the changes are happening during each iteration. It seems like the modifications are somehow discarded once the loop is exited. There must be something fundamental that I am overlooking. Any clues on where I might have gone wrong?