My situation involves two lists: accounts
and accountsWithSelectedField
. I initially mapped accountsWithSelectedField
like this:
this.accountsWithSelectedField = this.accounts.map(s => ({...s, selected: false}));
Subsequently, upon receiving a list of selected accounts called accountsSetups
from an http request, I need to update the mapping accordingly. The desired outcome should be as follows:
accounts: 111, 222, 333, 444
accountsWithSelectedField: {111: false}, {222: false}, {333: false}, {444: false}
accountSetups(from http): {222, true, true}, {333, true, false}
After mapping => accountsWithSelectedField: {111: false}, {222: true}, {333: true}, {444: false}
I am struggling with correctly mapping it, as my attempts either do not display the IBAN or result in all selections being marked as true.
this.accountsWithSelectedField = this.accounts.map(o => data.accountSetups.map(s => ({
iban: o.iban,
selected: s.someBoolean || s.anotherBoolean
})));
I have also tried another approach:
for (const account of this.accountsWithSelectedField) {
for (const acc of data.accountSetups) {
if (account.iban === acc.account.iban) {
console.log(account.iban + ' is true');
account.selected = true;
}
}
}
Although I achieved 3 out of 6 IBANs being marked as true correctly, all six were ultimately selected, which is puzzling to me.