Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

82
Visualizações
AlpineJs x-model value set not working to x-data out dive

Datatble Server Side Processing is dynamically comming from backend yajra datatable

  <div x-data="AppData()">
   <form>
    <input x-model="user.name" />
    <input x-model="user.age" />
   </form>
</div>`

<table id="datatable">
 <tr>
   <td>Jhone<td>
   <td>27<td>
 <td><button onclick="AppData().getEdit({name:'Jhone',age:27})">Edit<button><td>
</tr>
`

//AlpineJs Code For X-Data

<script>
   function AppData()
   {
     return {
       user:{},
       getEdit(user)
       {
         this.user = user;        
       }
  };
 }
</script>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You bind the input elements to non-existing object attributes. You need to define them before you bind them to an element. Furthermore the AppData().getEdit() does not work and is unnecessary. You can just set the user object with the respective data.

<div x-data="AppData()">
  <form>
    <input x-model="user.name" />
    <input x-model="user.age" />
  </form>

  <table id="datatable">
    <tr>
      <td>Jhone</td>
      <td>27</td>
      <td><button @click="user = {name: 'Jhone', age: '27'}">Edit</button></td>
    </tr>
  </table>
</div>

<script>
document.addEventListener('alpine:init', () => {
  Alpine.data('AppData', () => ({
    user: {
      name: '',
      age: ''
    },
  }))
})
</script>

Note that I moved the table into the main div, where Alpine.js' x-data directive is present, so the code in @click can access the component data.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda