резидент. js
state : {
residents: []
},
getters:{
getResidentsById: (state) => (id) => {
return state.residents.find(resident => resident.id === id)
}
}
Медикаментозное лечение. vue
data() {
return { medications: [],
},
computed: {
...mapGetters([
'allMedications', //this returns all the list of medication
'getResidentsById',
]),
},
method: {
getResidentName(id) {
const resident = this.getResidentsById(id)
return resident && resident.name
},
},
watch: {
allMedications() {
const medicationArray = this.allMedications
this.medications = medicationArray.map(medication =>
({
...medication,
residentName: this.getResidentName(medication.resident)
})
);
},
}
Я хотел установить residentName prop в список лекарств список, передав идентификатор резидента из лекарства. Я получаю undefined при вызове getResidentsById . Объект лекарства содержит резидентный ключ, значение которого является идентификатором резидента.