i have checked this but it is too hard to make a nested each to work in a table, the table has special XML structure that does not work ok when adding other loops.
you don't have other alternative that changing your data. but it can be done at runtime, no need to change how you send your data.
here is an example that reproduces what you want
0_1726155161621_export-docx-table.jsrexport (if this gets downloaded with a .bin extension, please rename to use the .jsrexport extension)
the trick is in the helpers
function getTableRows (source) {
const data = getTableData(source)
return data.slice(1).map((item) => [item])
}
function getTableColumns (source) {
const data = getTableData(source)
return [data[0]]
}
function getTableBackground (level) {
if (level === 2) {
return 'FFA08C'
} else if (level === 3) {
return 'FFFE3F'
}
return 'A7C3C0'
}
function getTableData (source) {
const data = []
const extract = (obj, currentLevel) => {
for (const key in obj) {
if (Array.isArray(obj[key])) {
for (const c of obj[key]) {
extract(c, currentLevel + 1)
}
} else if (typeof obj[key] === 'object' && obj[key] !== null) {
extract(obj[key], currentLevel + 1)
} else {
data.push({ value: { content: obj[key], level: currentLevel } })
}
}
}
extract(source, 1)
return data
}