Front-end Table Script Error

I have a front-end script that's filtering some JSON objects, displaying only a few key properties, using a map() call. The script works fine, but I'm getting an error every time it executes.
No description
No description
7 Replies
rubenf
rubenf2y ago
The error is that bg_0.result is undefined
Trevor Sullivan
Trevor SullivanOP2y ago
But it's not undefined ... it's working properly
Trevor Sullivan
Trevor SullivanOP2y ago
My items are populated in the result
No description
Trevor Sullivan
Trevor SullivanOP2y ago
Oh wait ... maybe it's undefined initially, but after bg_0 completes, it calls it again
rubenf
rubenf2y ago
Could you share a minimal reproduction of your app please
Trevor Sullivan
Trevor SullivanOP2y ago
Yup ... this is what was happening. I wrapped the result in an if statement.
if (bg_0.result != undefined) {
return bg_0.result.map(val => {
return {
name: val.name,
type: val.type,
status: val.status
}
})
}
else {
return []
}
if (bg_0.result != undefined) {
return bg_0.result.map(val => {
return {
name: val.name,
type: val.type,
status: val.status
}
})
}
else {
return []
}
rubenf
rubenf2y ago
you can also add ? in a few places bg_0.result?.map .... ?? []