Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
498 views
in Technique[技术] by (71.8m points)

javascript - Why Can't I see My Invoice Items When I Edit My Invoice?

I'm using Laravel 5.7 & VueJs 2.5.* ...

I'm using a single Bootstrap Model to create as well as edit my TicketInvoice & it's TicketInvocieItems, but when i hit Edit, Bootstrap Model opens & i see data fill with TicketInvoice but can't see data of TicketInvoiceItems. I don't know how to fill data of TicketInvoiceItems as well.

My ticketInvoiceItems input fields:

<tbody>
  <tr v-for="(ticketInvoiceItem, key) in form.ticketInvoiceItems" :key="key">
    <!--Passenger Name-->
    <td>
      <input v-model="ticketInvoiceItem.passenger_name" size="40" type="text" name="passenger_name" class="table-control form-control" :class="{ 'is-invalid': form.errors.has('passenger_name') }">
      <has-error :form="form" field="passenger_name"></has-error>
    </td>
    <!--Ticket No.-->
    <td>
      <input v-model="ticketInvoiceItem.ticket_no" size="24" type="text" name="ticket_no" class="table-control form-control" :class="{ 'is-invalid': form.errors.has('ticket_no') }">
      <has-error :form="form" field="ticket_no"></has-error>
    </td>
  </tr>
  <!----------- ANY MANY OTHER FIELDS DOWN BELOW ----------->

My HTML edit Button:

<a href="#" @click="editModel(ticketInvoice)">
  <i class="fas fa-user-edit fa-lg text-orange"></i>
</a>

My VueJs editModel() code:

<script>
  /*==============EDIT INVOICE CODE==============*/
  editModel(ticketInvoice) {
    this.editmode = true;
    this.form.reset();
    this.form.clear();
    $("#addNewTicketInvoice").modal("show");
    this.form.fill(ticketInvoice);
  },
  /*==============END EDIT INVOICE CODE==============*/
  </script>

My data() in VueJs

<script>
  export default {
    data() {
      return {
        editmode: true,
        ticketInvoices: {},
        vendors: null,
        form: new Form({
          id: "",
          vendor_id: "",
          ticket_invoice_no: "",
          ticket_invoice_date: "",
          ticket_invoice_fares_total: "",
          ticket_invoice_grand_total: "",

          ticketInvoiceItems: [{
            id: "",
            ticket_invoice_id: "",
            passenger_name: "",
            ticket_no: "",
            departure_date: "",
            fares: "",
            sub_total: 0
          }]
        })
      };
    },
    </script>

An Image For Better Understanding enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In your editModel method add these lines :

   $("#addNewTicketInvoice").modal("show");
   this.form.fill(ticketInvoice);
   this.form.ticketInvoiceItems=ticketInvoice.ticket_invoice_items;

this.form.ticketInvoiceItems will be an object to loop through its values you should use

   Object.values(this.form.ticketInvoiceItems).forEach(....

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...