From 6885f5ec49988a274590fd4f5c747765731adc91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E7=81=8F?= Date: Mon, 6 Jan 2020 10:36:41 +0800 Subject: [PATCH] Table prop: row-key suuport string --- src/components/table/table-body.vue | 2 +- src/components/table/table.vue | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/table/table-body.vue b/src/components/table/table-body.vue index 08a5d100..7e271b39 100644 --- a/src/components/table/table-body.vue +++ b/src/components/table/table-body.vue @@ -67,7 +67,7 @@ default: false }, rowKey: { - type: Boolean, + type: [Boolean, String], default: false } }, diff --git a/src/components/table/table.vue b/src/components/table/table.vue index db533b59..d17ba496 100644 --- a/src/components/table/table.vue +++ b/src/components/table/table.vue @@ -236,8 +236,9 @@ default: 'dark' }, // #5380 开启后,:key 强制更新,否则使用 index + // 4.1 开始支持 String,指定具体字段 rowKey: { - type: Boolean, + type: [Boolean, String], default: false }, // 4.0.0 @@ -959,7 +960,7 @@ let data = deepCopy(this.data); data.forEach((row, index) => { row._index = index; - row._rowKey = rowKey++; + row._rowKey = (typeof this.rowKey) === 'string' ? row[this.rowKey] : rowKey++; if (row.children && row.children.length) { if (row._showChildren) { row._isShowChildren = row._showChildren; @@ -976,7 +977,7 @@ return data.children.map((row, index) => { const newRow = deepCopy(row); newRow._index = index; - newRow._rowKey = rowKey++; + newRow._rowKey = (typeof this.rowKey) === 'string' ? row[this.rowKey] : rowKey++; if (newRow._showChildren) { newRow._isShowChildren = newRow._showChildren; } else {