javascript - VueJs 在表中的日期之间过滤

标签 javascript vue.js vuejs2 vuetify.js

我有一个问题要问你们,我有一个表格,其中包含该季度的学生时间信息和日期。我想添加一个时间选择器,以便教师可以选择仅显示该日期和当天之间的信息。

基本上,我想使用输入时间字段来过滤并仅显示从 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”。

关于javascript - VueJs 在表中的日期之间过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54132887/

相关文章:

javascript - 修复了导航栏隐藏网页内容的问题

javascript - 难以包装 javascript 行为并将其保留以备后用

vue.js - 在 VueJS 中更新多个数据

javascript - VueJs - 通过过渡更改 div 颜色

javascript - 如何在输入值=""内添加vue输出

javascript - 如何使用 Jquery 控制下拉选择选项菜单

javascript - 使用 .focus() 时,FireFox 弹出窗口阻止程序会破坏 javascript 应用程序

php - Laravel 5.2 CORS,GET 不使用预检选项

javascript - 如何将动态输入值绑定(bind)到 Vue.js 中的 v-for 输入字段

css - 如何将 CSS/SCSS 与 Vue 组件文件保持在一起