I'm running into an issue with Parse.Query and how to handle the result promise. Here's my current code snippet:
var ga = new Parse.Query(Game);
ga.include('away_team');
ga.include('home_team');
ga.equalTo("objectId", req.params.id);
ga.find().then(function(result){
console.log(result[0]);
});
The console log displays data like this:
{
"home_team" : {"name":"Dallas Stars", "arena":"American Airlines Center"},
"away_team" : {"name":"New York Rangers", "arena":"Madison Square Garden"},
"createdAt" : "2015-12-28T10:35:35.541Z"
}
The challenge I'm facing is extracting the name from away_team
within my promise function. When I attempt
console.log(results[0].away_team)
, it returns No message provided.
My desired output would be
{"name":"New York Rangers", "arena":"Madison Square Garden"}
. However, trying console.log(results[0].away_team.name)
results in a TypeError.
In order to achieve my goal of displaying the correct title in my view based on the teams playing, I need access to the team names. For example:
res.render('inside/game', {
title: result[0].away_team.name + " vs. " + result[0].home_team.name
// title: New York Rangers vs. Dallas Stars
});
Is it possible to accomplish this within the routing class?