Это безумие. Я читаю объект с веб-сервера и перебираю его, и я могу добавить свойства к объекту. Но когда я пытаюсь сделать новую карту самостоятельно, она не работает. Так просто, как я могу это сделать
// from the server and works
plans: any[];
sourceByPlan: any[];
// my own map for other purposes I try to fill
// as I loop through the items from the server
customMap: any[]; // also tried 'any'
var res = JSON.parse(response);
this.plans = res.plans; // where res.plans looks like [{value: "id", label: "readableid"}, {value: "id2", label: "otherreadable"}]
this.sourceByPlan = res.sources; // where res.sources looks like { id: [Object, Object, Object...]};
// loop through each source and add a property
for(var i = 0; i < this.plans.length; i++){
if(this.sourceByPlan[this.plans[i].value]){
for (var j = 0; j < this.sourceByPlan[this.plans[i].value].length; j++){
var sObj = this.sourceByPlan[this.plans[i].value][j];
var status = this.getStatus(sObj); // simple string
sObj["newstatus"] = status; // THIS WORKS AS EXPECTED
// here is where the new non working code starts
var key = this.plans[i].value + status ; // looks like 'asdf1234pending'
if (!customMap[key]) {
customMap[key] = [];
}
customMap[key].push(sObj); // this will still be empty
}
}
}
sObj не поставляется со свойством sObj.newstatus с сервера, но позволяет мне добавлять его по желанию. Я пытаюсь построить другую карту на лету, но каждый раз, когда я проверяю console.log (customMap), он каждый раз пуст. Логически это выглядит так же, как объект, который я получаю с сервера.