File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Expand file tree Collapse file tree 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', {
205205 } ,
206206
207207 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+ } )
209211 } ,
210212
211213 // event called when each item mounted or size changed
@@ -267,15 +269,16 @@ const VirtualList = Vue.component('virtual-list', {
267269 for ( let index = start ; index <= end ; index ++ ) {
268270 const dataSource = dataSources [ index ]
269271 if ( dataSource ) {
270- if ( Object . prototype . hasOwnProperty . call ( dataSource , dataKey ) ) {
272+ const uniqueKey = typeof dataKey === 'function' ? dataKey ( dataSource ) : dataSource [ dataKey ]
273+ if ( uniqueKey ) {
271274 slots . push ( h ( Item , {
272275 // key: dataSource[dataKey],
273276 props : {
274277 index,
275278 tag : itemTag ,
276279 event : EVENT_TYPE . ITEM ,
277280 horizontal : isHorizontal ,
278- uniqueKey : dataSource [ dataKey ] ,
281+ uniqueKey : uniqueKey ,
279282 source : dataSource ,
280283 extraProps : extraProps ,
281284 component : dataComponent ,
Original file line number Diff line number Diff line change 44
55export const VirtualProps = {
66 dataKey : {
7- type : String ,
7+ type : [ String , Function ] ,
88 required : true
99 } ,
1010 dataSources : {
You can’t perform that action at this time.
0 commit comments