I own a collection of car
models. Each individual car
is associated with a unique userid
. Furthermore, each user
model contains both a userid
and a corresponding username
.
In my view, I aim to showcase all of my car
models alongside their respective username
. However, I encounter difficulties when attempting to convert the userid
into a username
without explicitly storing the username
within the car
model. Below is an excerpt from my code:
navigatedTo() {
this.carsRepository.getCars().then((cars) => {
for (var i = 0; i < cars.length; ++i) {
var car = cars[i];
this.usersRepository.getUsers().then(() => {
car.username = this.usersRepository.findUserById(car.userid).then(() => {
console.log(car);
});
});
}
this.context.cars = cars;
});
}
Upon navigating to a particular page, the navigatedTo
function is invoked. Subsequently, I iterate through this.context.cars
. The main issue with the aforementioned code snippet lies in the absence of the car.username
attribute within the car
object.
Could you provide guidance on how I can utilize typescript/javascript to achieve this task?