如何打破 vuejs 中的 v-for 循环 [英] How to break a v-for loop in vuejs
问题描述
我有一个我在下面提到的代码段.我用过 vuejs 和 vuetifyjs.
I have a code segment that i have mentioned below. I have used vuejs with vuetifyjs.
<v-data-table v-bind:headers="headers" v-bind:items="uniqueSubjects">
<template slot="items" slot-scope="props">
<td class="text-xs-center">{{ props.index+1 }}</td>
<td class="text-xs-center">{{ month[new Date(props.item.daily_date).getMonth()] }},{{ props.item.student_id }}</td>
<td class="text-xs-center">{{ props.item.subjects.subject_name }}{{ props.item.subjects.id }}</td>
<template v-for="n in 31">
<template v-for="(mark,index) in resultsList">
<template v-if="new Date(mark.daily_date).getDate() == n && mark.subject_id == props.item.subject_id && mark.student_id == props.item.student_id">
<td class="text-xs-center">
{{ mark.daily_marks }}
</td>
</template>
<template v-else-if="index>=resultsList.length-1">
<td class="text-xs-center">-</td>
</template>
</template>
</template>
</template>
<template slot="pageText" slot-scope="{ pageStart, pageStop }">
From {{ pageStart }} to {{ pageStop }}
</template>
</v-data-table>
我想在内部 v-if
条件为真时中断我的 循环.在这里,我想从头到尾搜索内部循环.如果数据根据给定的条件匹配,我想中断循环.然后我想一次又一次地这样做.我怎样才能做到这一点?任何帮助,将不胜感激.提前致谢.
I want to break my <template v-for="(mark,index) in resultsList">
loop when the internal v-if
condition is true.
Here i want to search the inner loop from first to last.I want to break the loop if the data is matched depending on the given condition.and then i want to do it again and again.
How can I do that? Any help would be appreciated.
Thanks in advance.
推荐答案
没有办法破坏 v-for
.最好在您的组件中创建一个计算属性并在那里过滤您的数据以仅将需要的数据传递给 v-for
.
There is no way to break v-for
. It is better to create a computed property in your component and filter your data there to pass only needed data to v-for
.
例如:
// ... your component code
computed: {
validResultsList() {
return this.resultsList/* ... your filtering logic ... */;
}
}
// ... your component code
然后在您的模板中:
<template v-for="(mark,index) in validResultsList">
这篇关于如何打破 vuejs 中的 v-for 循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!