I have the following request in Get:
app.get('/attraction/:routeid', async(req,res)=>{
let response = await attraction_routes.findAll({
attributes: ['attractionId'],
where:{routeid: req.params.routeid},
raw: true,
include: [{
model: Attraction,
required: true,
attributes: ['Name','Desc','Address']
}],
order: [['id', 'ASC']]
});
res.json(response)
});
And it returns the following JSON:
[
{
"attractionId":1,
"Attraction.Name":"Mirante Cerro Santa Lucia",
},
{
"attractionId":2,
"Attraction.Name":"Cajon del Maipo",
}
]
I want to access the Attraction.Name attribute in the rendering of my item on my page, but when I define it in my variable there is an error *undefined is not an object (evaluating 'item.Attraction.Name') *
function renderPost(item){
return(
<View style={styles.card}>
<Text style={styles.title}>
{item.Attraction.Name}
</Text>
</View>
)
};
CodePudding user response:
The key itself has a dot, so you need to do:
<Text style={styles.title}>
{item['Attraction.Name']}
</Text>
The way you currently have it would work for:
{
"attractionId":2,
"Attraction": {
"Name":"Cajon del Maipo"
}
}