-
Notifications
You must be signed in to change notification settings - Fork 12
Feature Request: Each tag #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Maybe |
I'm looking at doing this - I need it for doing something like this: <table>
<tbody>
<each condition="item, item.id in list">
<tr>
<td>...</td>
</tr>
<tr if="item.isExpanded"> // include a second edit row
<td>...</td>
</tr>
</each>
</tbody>
</table> The realisation I have encountered is around incremental-dom The above code would need to become something like this below: <table>
<tbody>
<each condition="item, item.id in list">
<tr key="{item.id}_item">
<td>...</td>
</tr>
<tr if="item.isExpanded" key="{item.id}_edit"> // include a second edit row
<td>...</td>
</tr>
</each>
</tbody>
</table> Or, making use of the transient $key autogenerated uuid variable available within the for loop: <table>
<tbody>
<each condition="item, item.id in list">
<tr key="{$key}_item">
<td>...</td>
</tr>
<tr if="item.isExpanded" key="{$key}_edit"> // include a second edit row
<td>...</td>
</tr>
</each>
</tbody>
</table> I don't really like the fact we lose autogenerated keys - it's easy to forget to put one on and the consequence is your dom tree will likely get out of sync. I just can see an alternative ATM. |
|
I like it but I'm not sure this solves my issue though. Regardless whether we name it |
Also other intuitive option |
@davidjamesstone: I only looked at the superviews transformation code briefly, so this is a little bit shooting from the hip, but can you do something similar to reference counting? — make the handler onopentag and onclosetag functions closures that reference a variable to track nested tag depth and if you're inside an each. If you're inside an each, increment on open, decrement on close, and if you're at the root inside an each, add a key. I'm not sure how self-closing tags are handled, but you may need to keep a list of those and just not increment on them. |
I also have a need for a standalone each. I have two different The bulk of the authoring was done last summer with a brief flurry in November. Is this an active project/library for you? (Just asking sincerely.) |
Yeah I really need to look at implementing this. It seems it would be quite a useful feature. It still an active project yes. I use it for a lot of my own projects, I just haven't had to change it much over the last few months. I'm keeping an eye on the idom project and plan to keep it aligned with their api as it matures. |
Fantastic blikblum. I'll take a look over it later. What other features does your branch contain? I'm wondering if I should bring it all over, including the unit tests et al. Many thanks |
I implemented the following:
Also planning:
|
Proposal:
Add an
<each>
tag that functions similar to the dual<if>
, which can be used as an attribute or as its own node.each
would take a single attribute,condition
.Syntax:
Reason:
<div each="item in list" if="true">{$value}</div>
has two different potential meanings:and
however, only the latter example is possible with the current syntax.
The text was updated successfully, but these errors were encountered: