How can I assign a key index in array with Vuejs

  laravel, vue.js

Hi I have a form like this:

<tr v-for="(post, index) in posts" v-bind:index="index">
   <td>{{ post.rut }}</td>
   <td>{{ post.names }} {{ post.father_lastname }} {{ post.mother_lastname }}</td>
      <input type="number" class="form-control" id="exampleInputEmail1" v-model="form.amount[index]" placeholder="Ingresa el monto">

How you can see it has v-model="form.amount[index]" but what I want to do it’s this:

 <input type="number" class="form-control" id="exampleInputEmail1" v-model="form.amount[post.rut]" placeholder="Ingresa el monto">

I mean I ant to assign my own index my custom index I wonder how can I do that??

My vuejs code is this:

   data: function() {
        return {
            form: {
                amount: [],

I declared amount array in vuejs how you can see above but I need to assign my own index in array because if I send the data and I check the array in this moment, it is:

 0 => value, 1 => value

but I need to do this

'2714155' =>  value, '4578745' => value...

how can I do that? Thanks

Source: Laravel

Leave a Reply