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

fix(RecycleScroller): when updating items by splice, the index always… #809

Open
wants to merge 1 commit into
base: v1
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/vue-virtual-scroller/src/components/RecycleScroller.vue
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ export default {
},

simpleArray,
itemIndexByKey () {
const { keyField, items } = this
const result = {}
for (let i = 0, l = items.length; i < l; i++) {
result[items[i][keyField]] = i
}
return result
},
},

watch: {
Expand Down Expand Up @@ -366,6 +374,7 @@ export default {
const views = this.$_views
const unusedViews = this.$_unusedViews
const pool = this.pool
const itemIndexByKey = this.itemIndexByKey
let startIndex, endIndex
let totalSize
let visibleStartIndex, visibleEndIndex
Expand Down Expand Up @@ -493,7 +502,7 @@ export default {
if (view.nr.used) {
// Update view item index
if (checkItem) {
view.nr.index = items.indexOf(view.item)
view.nr.index = itemIndexByKey[view.item[keyField]]
}

// Check if index is still in visible range
Expand Down