Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
actualizar x-for de Ajax - Alpine Js

¿Cómo puedo decirle a Alpine que actualice x-for desde el servidor? En otras palabras, cómo forzar la actualización en AlpineJs.

 <select id="branches" name="branches" x-data="ajax" > <option value="" disabled selected="">Choose</option> <template x-for="branche in branches"> <option :value="branche.ID" x-text="branche.Branch_name"></option> </template> </select>
 document.addEventListener('alpine:init', () => { Alpine.data('ajax', () => ({ async branches() { return await $.post("path-url", { tb: "branches" }, (data) => { return data; }); } })) })
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Suponiendo que $.post es de jQuery :

 <select id="branches" name="branches" x-data="getBranches()"> <option value="" disabled selected="">Choose</option> <template x-for="branch in branches"> <option :value="branch.ID" x-text="branch.Branch_name"></option> </template> </select> <script> document.addEventListener('alpine:init', () => { Alpine.data('getBranches', () => ({ branches: [], init() { $.post("path-url", { tb: "branches" }, (data) => { this.branches = data }) } })) }) </script>

Usamos el método init() para obtener los datos, que se ejecuta antes de renderizar el componente. No tiene que "forzar" la actualización, simplemente mute una variable de datos reactiva de Alpine.js y Alpine.js actualizará el DOM poco después.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!