B
B
BarneyGumble2021-04-01 13:58:51
Vue.js
BarneyGumble, 2021-04-01 13:58:51

How to write v-if for the case if the total array contains at least one element with the desired value?

I'm just learning Vue, there is a small issue that I'm blunted on.

Now there is a condition to display the block if the offer code is 156:

<div v-for="offer in tour.offers" v-if="offer.code == 156">
    <div class="vue-night tables_cell">
        <div class="vue-text vue-line">{{ offer.nights }}</div>
    </div>
    <div class="vue-room tables_cell">
        <div class="vue-text vue-line">{{ offer.room_name }}</div>
        <div class="vue-tip">{{ offer.room_name }}</div>
    </div>
</div>


Now the condition has changed a bit and it is necessary to display the block if the offer code is 156 and if there is at least one offer in the general tour.offers array, where "offer.nights == 14"

How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Anton, 2021-04-01
@Fragster

https://developer.mozilla.org/ru/docs/Web/JavaScri...
In general, I would make a calculated property that returns an offer or null / undefined from the entire array of offers, which would be displayed (or not displayed), the cycle is in the layout here nafig is not needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question