Skip to content

Commit 47bff8f

Browse files
committed
Update data-key getter function
1 parent b491d0c commit 47bff8f

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ More usages or getting start you can refer to these clearly [examples](https://g
121121

122122
### Required props
123123

124-
| **             Prop             ** | **Type** | **Description** |
125-
|------------------|---------------|---------------------------------------------------------------------------------------------------------------------------------------------------|
126-
| `data-key` | String\|Function | The unique key get from `data-sources` in each data object, or generated by the attributes in each data object of `data-sources`. Its value **must be unique** in `data-sources`, it is used for identifying item size. |
127-
| `data-sources` | Array[Object] | The source array built for list, each array data must be an object and has an unique key for `data-key` property. |
128-
| `data-component` | Component | The render item component created / declared by vue, and it will use the data object in `datas-sources` as render prop and named: `source`. |
124+
| **             Prop             ** | **Type** | **Description** |
125+
|------------------|------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
126+
| `data-key` | String\|Function | The unique key get from `data-sources` in each data object. Or a function called with each `data-source` and return their unique key. Its value **must be unique** in `data-sources`, it is used for identifying item size. |
127+
| `data-sources` | Array[Object] | The source array built for list, each array data must be an object and has an unique key get or generate for `data-key` property. |
128+
| `data-component` | Component | The render item component created / declared by vue, and it will use the data object in `data-sources` as render prop and named: `source`. |
129129

130130
### Optional props
131131

@@ -134,7 +134,7 @@ More usages or getting start you can refer to these clearly [examples](https://g
134134
<p></p>
135135
<table>
136136
<tr>
137-
<th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Props&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
137+
<th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Prop&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
138138
<th>Type</th>
139139
<th>Default</th>
140140
<th>Description</th>
@@ -155,7 +155,7 @@ More usages or getting start you can refer to these clearly [examples](https://g
155155
<td><code>estimate-size</code></td>
156156
<td>Number</td>
157157
<td>50</td>
158-
<td>The estimate size of each item, if it is closer to the average size, the scrollbar length looks more accurately. It is recommended to assign the average that calculate by yourself.</td>
158+
<td>The estimate size of each item, if it is closer to the average size, the scrollbar length looks more accurately. It is <strong>recommended</strong> to assign the average that calculate by yourself.</td>
159159
</tr>
160160
</table>
161161
</details>
@@ -165,7 +165,7 @@ More usages or getting start you can refer to these clearly [examples](https://g
165165
<p></p>
166166
<table>
167167
<tr>
168-
<th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Props&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
168+
<th>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Prop&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
169169
<th>Type</th>
170170
<th>Default</th>
171171
<th>Description</th>
@@ -278,6 +278,12 @@ More usages or getting start you can refer to these clearly [examples](https://g
278278
<td>{}</td>
279279
<td>Item wrapper element inline style.</td>
280280
</tr>
281+
<tr>
282+
<td><code>item-scoped-slots</code></td>
283+
<td>Object</td>
284+
<td>{}</td>
285+
<td>The <code>$scopedSlots</code> for item component.</td>
286+
</tr>
281287
<tr>
282288
<td><code>header-tag</code></td>
283289
<td>String</td>
@@ -314,12 +320,6 @@ More usages or getting start you can refer to these clearly [examples](https://g
314320
<td>{}</td>
315321
<td>For using using footer slot, footer slot wrapper element inline style.</td>
316322
</tr>
317-
<tr>
318-
<td><code>item-scoped-slots</code></td>
319-
<td>Object</td>
320-
<td>{}</td>
321-
<td>The <code>$scopedSlots</code> for item component</td>
322-
</tr>
323323
</table>
324324
</details>
325325

src/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,8 @@ const VirtualList = Vue.component('virtual-list', {
205205
},
206206

207207
getUniqueIdFromDataSources () {
208-
return this.dataSources.map((dataSource) => {
209-
return typeof this.dataKey === 'function' ? this.dataKey(dataSource) : dataSource[this.dataKey]
210-
})
208+
const { dataKey } = this
209+
return this.dataSources.map((dataSource) => typeof dataKey === 'function' ? dataKey(dataSource) : dataSource[dataKey])
211210
},
212211

213212
// event called when each item mounted or size changed
@@ -270,9 +269,8 @@ const VirtualList = Vue.component('virtual-list', {
270269
const dataSource = dataSources[index]
271270
if (dataSource) {
272271
const uniqueKey = typeof dataKey === 'function' ? dataKey(dataSource) : dataSource[dataKey]
273-
if (uniqueKey) {
272+
if (typeof uniqueKey === 'string' || typeof uniqueKey === 'number') {
274273
slots.push(h(Item, {
275-
// key: dataSource[dataKey],
276274
props: {
277275
index,
278276
tag: itemTag,

0 commit comments

Comments
 (0)