sorting - 为什么“_.orderBy”函数不对结果进行排序?
问题描述
我想做数据排序,但我不知道为什么它不起作用。我已经为此苦苦挣扎了几个小时,但我仍然不知道出了什么问题。有人能告诉我为什么“_.orderBy”函数不对结果进行排序吗?
<template>
<div>
<table>
<thead>
<tr>
<th v-for="(column, index) in columns" :key="index">
<a href="#" @click="sortBy(index)">{{ column }}</a>
</th>
</tr>
</thead>
<tbody>
<tr v-for="user in orderedUsers" :key="user.id">
<td>{{ user.name }}</td>
<td>{{ user.age }}</td>
</tR>
</tbody>
</table>
</div>
<script>
export default {
data() {
return {
users: [
{name: 'Andrew', age: 100},
{name: 'Bella', age: 200},
{name: 'Cylerion', age: 300},
],
columns: {
name: 'User Name',
age: 'User Age'
},
sortKey: 'name',
reverse: false
}
},
computed: {
orderedUsers: function () {
return _.orderBy(this.users, this.sortKey, this.reverse)
}
},
methods: {
sortBy: function(sortKey) {
this.reverse = (this.sortKey == sortKey) ? ! this.reverse : false;
this.sortKey = sortKey;
},
}
}
</script>
我的图书馆:Lodash 4.6.0。
解决方案
推荐阅读
- java - Printing backtraces when debugging java
- wpf - WPF TreeView share size of grid column in single level
- c++ - 如何创建 char/std::byte 的 std::vector,其中第一个字节与 16 个字节对齐,但没有填充?
- javascript - 派生类是否更新其父类属性?
- python - 来自seaborn的颜色强度错误
- sql - SQL - 将逗号分隔的字符串转换为单独的行后更新表
- erlang - 当我将 ets 表转换为 Erlang 中的列表时,如何减少进程的内存使用量?
- spring - PathVariable 中的正则表达式无法正常工作 Spring
- git - 通过 cPanel 添加私有 git 仓库
- javascript - 如何延迟函数或如何在绘图中使用 settimout