File tree 2 files changed +7
-4
lines changed
2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -205,7 +205,9 @@ const VirtualList = Vue.component('virtual-list', {
205
205
} ,
206
206
207
207
getUniqueIdFromDataSources ( ) {
208
- return this . dataSources . map ( ( dataSource ) => dataSource [ this . dataKey ] )
208
+ return this . dataSources . map ( ( dataSource ) => {
209
+ return typeof this . dataKey === 'function' ? this . dataKey ( dataSource ) : dataSource [ this . dataKey ]
210
+ } )
209
211
} ,
210
212
211
213
// event called when each item mounted or size changed
@@ -267,15 +269,16 @@ const VirtualList = Vue.component('virtual-list', {
267
269
for ( let index = start ; index <= end ; index ++ ) {
268
270
const dataSource = dataSources [ index ]
269
271
if ( dataSource ) {
270
- if ( Object . prototype . hasOwnProperty . call ( dataSource , dataKey ) ) {
272
+ const uniqueKey = typeof dataKey === 'function' ? dataKey ( dataSource ) : dataSource [ dataKey ]
273
+ if ( uniqueKey ) {
271
274
slots . push ( h ( Item , {
272
275
// key: dataSource[dataKey],
273
276
props : {
274
277
index,
275
278
tag : itemTag ,
276
279
event : EVENT_TYPE . ITEM ,
277
280
horizontal : isHorizontal ,
278
- uniqueKey : dataSource [ dataKey ] ,
281
+ uniqueKey : uniqueKey ,
279
282
source : dataSource ,
280
283
extraProps : extraProps ,
281
284
component : dataComponent ,
Original file line number Diff line number Diff line change 4
4
5
5
export const VirtualProps = {
6
6
dataKey : {
7
- type : String ,
7
+ type : [ String , Function ] ,
8
8
required : true
9
9
} ,
10
10
dataSources : {
You can’t perform that action at this time.
0 commit comments