【发布时间】:2019-04-04 10:43:51
【问题描述】:
我正在尝试使用 Vue JS 2 根据单击表格行中的表格标题对 HTML 表格的数据进行排序。
我已经实现了第一列的排序。但是,由于某种原因,可能是一些语法问题,其余列的排序不起作用。
在 HTML 中,排序函数的参数对我来说似乎有问题。
<th v-for="(toolAttribute, index) in results.toolAttribute" :key="index" @click="sort('info.value')" class="header">{{toolAttribute.attributeName}}</th>
查看JS文件的东西:
computed:{
sortedResults:function() {
return this.results.device.sort(function(a,b){
let modifier = 1;
if(this.currentSortDir === 'desc') modifier = -1;
if(a[this.currentSort] < b[this.currentSort]) return -1 * modifier;
if(a[this.currentSort] > b[this.currentSort]) return 1 * modifier;
return 0;
}.bind(this));
}
}
具体来说:
return this.results.device.sort(function(a,b)
这是相同的小提琴:
【问题讨论】:
-
我认为您可以轻松使用 Vuetify 提供的 DataTable 组件。这是link。
-
看来这将是用 Vuetify 对代码进行重大改写
-
请定义什么是第一位的?
[{value: false}, {value: false}, {value: false}] or [{value: true}, {value: false}, {value: true}],在您当前的示例中,这没有定义
标签: vue.js