Trevor Sullivan
Trevor Sullivan17mo ago

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
rubenf17mo ago
The error is that bg_0.result is undefined
Trevor Sullivan
Trevor SullivanOP17mo ago
But it's not undefined ... it's working properly
Trevor Sullivan
Trevor SullivanOP17mo ago
My items are populated in the result
No description
Trevor Sullivan
Trevor SullivanOP17mo ago
Oh wait ... maybe it's undefined initially, but after bg_0 completes, it calls it again
rubenf
rubenf17mo ago
Could you share a minimal reproduction of your app please
Trevor Sullivan
Trevor SullivanOP17mo 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
rubenf17mo ago
you can also add ? in a few places bg_0.result?.map .... ?? []