-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Refs inside each blocks #368
Comments
You could call it I suppose if it's documented well enough, anything would work OK here :) |
IMHO sticking with |
I agree. I thought it would be like that until I checked the docs and saw it isn't available yet. Makes sense to me. |
In this example: {{#each rows as y}}
{{#each columns as x}}
<div ref:cells/>
{{/each}}
{{/each}} Supposing that A contrived example: {{#each rows as y, yIndex}}
{{#each columns as x, xIndex}}
<Cell ref:cells isOddRow="{{yIndex % 2 > 0}}" />
{{/each}}
{{/each}}
<button on:click="color()">color odd rows</button>
<script>
export default {
methods: {
color() {
(this.ref.cells || []).forEach(cell => {
if (cell.get('isOddRow')) {
cell.set({ hoverColor: 'green' })
}
})
}
}
}
</script> |
I just ran into a use case where I wanted an array of refs to elements inside an |
@Rich-Harris pointed me to this issue when I raised this in the chat room (although note my need was simply to loop within a method, rather than an #each block): "Wish this.refs was an array of refs rather than an object - or we had a this.children array of any child components. I've a page with 6 graphs and other stuff and wanted to simply loop through and refresh any graphs, doesn't look like it is possible and for now I have to hard-code it" I'd suspect this will be a more common need the more users start using svelte. |
|
How about something like:
|
Closing as this will be fixed in v3 (with |
Currently they're not allowed, but maybe this...
...could result in
component.refs.things
being an array. The array need not correspond to theeach
block expression, since you might have things like this:Or is it confusing having two subtly different meanings for
ref
?The text was updated successfully, but these errors were encountered: