javascript - VueJs过滤表中的日期
问题描述
我有一个问题要问你们,我有一个包含本季度学生时间信息和日期的表格。我想添加一个时间选择器,以便教师可以选择仅显示该日期和那一天之间的信息。
基本上,我想使用进入时间字段来过滤和显示从 x 日期到 x 日期的数据。
这是我的代码
<v-card>
<v-card-title>
Student Profile
<v-spacer></v-spacer>
</v-card-title>
<v-data-table :headers="headers2"
:pagination.sync="pagination2"
:items="profile"
:search="search">
<template slot="items" slot-scope="props">
<td>{{ props.item.sid }}</td>
<td class="text-xs-left">{{ props.item.firstName }}</td>
<td class="text-xs-left">{{ props.item.lastName }}</td>
<td class="text-xs-left">{{ props.item.course }}</td>
<td class="text-xs-left">{{ props.item.entryTime }}</td>
<td class="text-xs-left">{{ props.item.exitTime }}</td>
<td class="text-xs-left">{{ props.item.duration }}</td>
</template>
<v-alert slot="no-results" :value="true" color="error" icon="warning">
Your search for "{{ searchQuery }}" found no results.
</v-alert>
</v-data-table>
</v-card>
方法
methods: {
editStudent(sid) {
this.dialog = true;
this.editedSid = sid;
axios.get('/api/e', {
params: {
'sid': this.editedSid
}
}).then(response => {
this.profile = response.data
}).catch(e => {
console.log(e)
})
}
}
有什么建议么?
解决方案
您要做的是添加一个过滤原始数据的“计算属性”,然后使用它。
就像是
computed: {
filteredEntries(){
return this.profile.filter(entry => {
//check if the entry is between the selected dated
});
}
}
然后在初始化表时使用“this.filteredEntries”而不是“this.profile”。
推荐阅读
- xml - 收到错误“System.Xml.XmlException:根级别的数据无效。第 1 行,位置 1。
- mysql - 在再次授予之前清除启动时的 MySQL 授予
- python - 如何使用 torchvision 的导入数据集访问 MNIST 数据的各个数据点并从 trainset 对象检查它们的大小、形状等
- scala - 使用 Scala Futures 按顺序执行依赖项
- macos - 如何在 Open Firmware 中取消设置环境变量?
- node.js - 在云功能上使用 puppeteer 拒绝访问网站
- haskell - 在 Haskell 中进行凸优化的最佳方法?
- javascript - 在Vuejs / Java应用程序中选择未定义的对象数组中的特定对象
- list - vmware_tag_manager, list to string 麻烦
- sql - 通过 SQLalchemy 更新 PosgreSQL 数据库;语法错误