0

I want to show the schedule, with if condition. If the index in the loop is the same as the index day, then display 'index' else is '-'.

for now, this is my view:

enter image description here

My code:

<td v-for="(n, i) in 7" :key="i">
    <span :key="index" v-for="(item, index) in item.schedule_detail">
        <span v-if="item.day === i">
            <span>{{ item.day }}</span>
        </span>
        <span v-else>-</span>
    </span>
</td>

My expectations:

enter image description here

Thanks a lot.

2
  • show the item.schedule_details data Commented Oct 16, 2020 at 9:56
  • this is the data: result Commented Oct 20, 2020 at 7:43

1 Answer 1

0

This v-if logic should work fine. See the below code

new Vue({
  el: '#app',
  data: {
    item: {
      schedule_detail: [{
          "id": 1,
          "doctor_schedule_id": 1,
          "day": 0,
          "from_time": "08:00:00",
          "until_time": "12:00:00",
          "from_time_2": "17:00:00",
          "until_time_2": "21:00:00",
        },
        {
          "id": 2,
          "doctor_schedule_id": 1,
          "day": 2,
          "from_time": "08:00:00",
          "until_time": "21:00:00",
          "from_time_2": null,
          "until_time_2": null,
        }
      ]
    }
  }

})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>

<div id='app'>
  <td><span :key="index" v-for="(i, index) in 7">
       <span v-if= "(i=item.schedule_detail.findIndex(x=>x.day===index)) >=0 ">
       {{item.schedule_detail[i].day}}
       </span>
    <span v-else>-</span>
    </span>
  </td>
</div>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.