Best way to dynamically change number and content of <OPTION> in <SELECT> from a fetch promise #4288
Replies: 3 comments 1 reply
-
Use x-init: https://postsrc.com/code-snippets/how-to-feetch-api-in-alpine-js |
Beta Was this translation helpful? Give feedback.
-
You can use x-init, or init method on the data to get it on load. You can have a method that fetches it and changes the data inline if you want it reactive to some other values. (not alpine, but make sure you also have |
Beta Was this translation helpful? Give feedback.
-
Thanks for all replies! I finally decided to go the Alpine.store() way, like this:
It may not be mandatory but just in case i need to update from outside the context of Alpine components. Best regards |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm needing help to change the number of options in a select when a "fetch" promise is executed.
Scenario: On page load a fetch is done in order to bring a json with values. I'd like to update (expand) the number of options in a select according to the data received.
I'd like to update "canales" and kind of re-render that select for the user. Of course the above code will not do...
Which would be the best way to do this?
Thanks in advance for your help!
Alex
Beta Was this translation helpful? Give feedback.
All reactions