Skip to content

Commit 4c9278e

Browse files
tiptronictangbc
authored andcommitted
Using dataSource[dataKey] leads to false results
Using `dataSource[dataKey]` has 2 issues: 1. It searches the complete prototype chain (which is unefficient) 2. If the resolved value is `0` or `false` the result is `false` (which isn't intended) Example: dataKey is 'id', it's value is zero: e.g. { id: 0 } So better to be explicit here, e.g. 👍 ` if(dataSource.hasOwnProperty(dataKey)) `
1 parent ee15067 commit 4c9278e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ const VirtualList = Vue.component('virtual-list', {
224224
for (let index = start; index <= end; index++) {
225225
const dataSource = dataSources[index]
226226
if (dataSource) {
227-
if (dataSource[dataKey]) {
227+
if(dataSource.hasOwnProperty(dataKey)) {
228228
slots.push(h(Item, {
229229
props: {
230230
index,

0 commit comments

Comments
 (0)