Open monochromer opened 1 year ago
Hey @monochromer,
Very late but I just ran into the same issue as you -- it seems that with nested webc:for
loops, a child element with a for loop on it can't access any loop values from a parent loop -- only current loop and global variables.
So in your instance for <td webc:for="column of columns" @text="item[column]"></td>
, you're able to have the column
value but not the item
value since it's in the parent loop.
Having spent the last day looking at this, luckily it seems JavasScript render functions can solve this(alternatively you could use template syntax as well).
Since the JavaScript render has access to all variables in the stack, what worked for me and I would imagine should work for you is to replace:
<tr webc:for="item of items">
<td webc:for="column of columns" @text="item[column]"></td>
</tr>
with
<tr webc:for="item of items">
<script webc:type="js">
let html = '';
for(column of columns){
html += `<td>${item[column]}</td>`;
}
html;
</script>
</tr>
Just for awareness -- it seems webc has some issues with table elements as well. Probably worth reading my other issue #183 and PR
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
: