E
E
Eugene2021-12-20 15:50:12
Vue.js
Eugene, 2021-12-20 15:50:12

How to correctly handle the condition when drawing the list?

Tell me how to correctly add a condition and draw another row in the table when the list is drawn.
Those. if my object has the "total" key, I want to add one more line ....
It's not clear where I should write v-if="item.total"

<table>
    <thead>.....</thead>
    <tbody>
        <tr v-for="item in data" :key="item.id">
            <td>{{ item.value1 }}</td>
            <td>{{ item.value2 }}</td>
            <td>{{ item.value3 }}</td>
            // Как мне правильно прописать условие v-if, что бы я мог при наличии ключа "total"  добавить ещё одну строку таблици
            // на js при переборе массива через forEach, я бы просто добавил: '</tr><tr><td colspan="3">{{ item.total }}</td>
        </tr>
    </tbody>
</table>


// Грубо говоря в итоге я хочу получить вот так
<table>
    <thead>.....</thead>
    <tbody>
        <tr>
            <td>....</td>
            <td>....</td>
            <td>....</td>
        </tr>
        <tr>
            <td>....</td>
            <td>....</td>
            <td>....</td>
        </tr>
        <tr>
            <td>....</td>
            <td>....</td>
            <td>....</td>
        </tr>
        <tr>
            <tr><td colspan="3">total</td>       
        </tr>
    </tbody>
</table>

Answer the question

In order to leave comments, you need to log in

5 answer(s)
0
0xD34F, 2021-12-20
@atachrus

<tbody>
  <template v-for="item in data">
    <tr>...</tr>
    <tr v-if="...">...</tr>
  </template>
</tbody>

I
IceJOKER, 2015-07-31
@IceJOKER

I think it's better to do without the regex in this case.

$str = 'Toster классный сайт';
$final_str = mb_substr($str, mb_strpos($str, ' '));

But if it's still a regular expression:
$str = 'Toster классный сайт';
$final_str = preg_replace('~^(.*?)\s~', '', $str);
var_dump($final_str);

F
FuriousAngel, 2015-07-31
@FuriousAngel

Find the position of the first occurrence of the space character in the string, remove from the string the number of characters from the beginning equal to the space position.
$str=strpos($row, " ");
$row=substr($row, 0, $str);

B
Baha Rustamov, 2015-07-31
@by133312

Thanks everyone, I did it :)
/^(\S+)\s+/

A
Alexander Aksentiev, 2015-07-31
@Sanasol

Regulators are evil.
explode()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question