Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第九章 实例--使用Render函数开发排序的表格组件 书 P170 #112

Open
amanisky opened this issue Aug 1, 2019 · 0 comments
Open

Comments

@amanisky
Copy link

amanisky commented Aug 1, 2019

sortByAsc 方法中
this.currentColumns[index]._sortType = 'asc'
sortByDesc 方法中
this.currentColumns[index]._sortType = 'desc'
上面两处的写法,点击排序时候不会触发 render 函数重新渲染
参考 Vue 官方文档:https://cn.vuejs.org/v2/guide/list.html#数组更新检测
代码修改如下
sortByAsc (key) {
let field = this.currentColumns[key].key
this.currentColumns = this.currentColumns.map((col, index) => Object.assign(col, { _sortType: index == key ? 'asc' : 'normal' }))
this.currentData.sort((a, b) => a[field] > b[field] ? 1 : -1)
},
sortByDesc (key) {
let field = this.currentColumns[key].key
this.currentColumns = this.currentColumns.map((col, index) => Object.assign(col, { _sortType: index == key ? 'desc' : 'normal' }))
this.currentData.sort((a, b) => a[field] < b[field] ? 1 : -1)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant