data-wp-each is there an iterator available? #63901
Closed
webconstructor
started this conversation in
Interactivity API
Replies: 1 comment 3 replies
-
You can use derived state for that. <div data-wp-context='{"answers": ["yes","no","unknown"]}'>
<template data-wp-each="context.answers">
<input data-wp-bind--id="state.myUniqueId" />
</template>
</div> store('myPlugin', {
state: {
get myUniqueId() {
const { item } = getContext();
return `somethingSpecific${item}`;
},
},
}); https://stackblitz.com/edit/interactivity-api-xsytbi-idboa9?file=index.html,main.js Does that make sense? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to make accessable radiobuttons like in
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label
Id's can be used only once on a page.
So what I like to have available is an iterator like in vue.js which I can concatinate with some string in order to not have id's be more than once on the page.
Preferably in the html.
vue.js :
How should this be done?
I am looking voor some sort of template string like solution:
Here some code of what it's use may look like.
If there is a preferred way of doing this entirely different in the interactivity api I love to hear...
p.s.
what is the correct way to combine dynamic & static data:
Beta Was this translation helpful? Give feedback.
All reactions