There are data that need to be output in the form of a table - an array of people and an array of fields
// index.11tydata.js
module.exports = {
users: [
{
id: 1,
name: 'Alex',
email: 'alex@example.com'
},
{
id: 2,
name: 'Bob',
email: 'bob@example.com'
},
{
id: 3,
name: 'Steave',
email: 'steave@example.com'
}
],
columns: ['id', 'name', 'email']
}
There is a component to which I pass data:
<c-data-table :@columns="columns" :@items="users"></c-data-table>
Here is the implementation of the component:
<table>
<thead>
<tr>
<th webc:for="column of columns" @text="column"></th>
</tr>
</thead>
<tbody webc:if="items?.length > 0">
<tr webc:for="item of items">
<td webc:for="column of columns" @text="item[column]"></td>
</tr>
</tbody>
</table>
I get an error about an unavailable variable item:
[11ty] 1. Having trouble rendering webc template ./src/pages/index/index.webc (via TemplateContentRenderError)
[11ty] 2. Check the dynamic attribute: `@text="item[column]"`.
[11ty] Original error message: Cannot read properties of undefined (reading 'id') (via Error)
[11ty]
[11ty] Original error stack trace: Error: Check the dynamic attribute: `@text="item[column]"`.
There are data that need to be output in the form of a table - an array of people and an array of fields
There is a component to which I pass data:
Here is the implementation of the component:
I get an error about an unavailable variable
item: