0
<modal :width="1000" :height="100" name="list-programs">
    <select name="" id="program" class="form-control" @change="onAddProgram()">
        <option>...</option>
        <option v-for="item, index in programlist" v-if="item" :value="index">{{ item.print_code + ' - ' + item.title }}</option>
    </select>
</modal>

<table class="table dataTable">
    <tr>
        <th>Программа</th>
        <th>Сумма по программе</th>
    </tr>
    <tr v-for="(item, index) in data" @click="onSelectedProgram(index)" :class="{'active-tr': selectedProgramIndex === index}" style="border: 1px solid black">
        <td>{{ programlist[index].print_code + " - " + programlist[index].title  }}</td>
        <td>{{ programlist[index].summa }}</td>
    </tr>
</table>

onAddProgram() {
    let index = $("#program option:selected").val();
    this.data[index] = []
    this.hide('list-programs')
    console.log(this.data)
},

При добавлении не работает перебор внутри таблицы.

Для дальнейшего кода мне надо чтобы индексы элементов programlist был индексов массива data

1

1 ответ 1

0

Для перебора массива лучше использовать следующую конструкцию:

<controll v-for="row in rows"
                  v-bind:key="row.id"
                  v-bind:id="row.id"
                  v-bind:title="row.title"
                  v-bind:subtitle="row.subtitle">
</controll>

Попробуйте исправить

   <tr v-for="(item, index) in data" @click="onSelectedProgram(index)" :class="{'active-tr': selectedProgramIndex === index}" style="border: 1px solid black">
        <td>{{ programlist[index].print_code + " - " + programlist[index].title  }}</td>
        <td>{{ programlist[index].summa }}</td>
    </tr>

на

  <tr v-for="item in data" @click="onSelectedProgram(index)" :class="{'active-tr': selectedProgramIndex === index}" style="border: 1px solid black">
        <td>{{ item.print_code + " - " + item.title  }}</td>
        <td>{{ item.summa }}</td>
    </tr>

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.