Table prop: row-key suuport string

This commit is contained in:
梁灏 2020-01-06 10:36:41 +08:00
parent 6118c2c8d1
commit 6885f5ec49
2 changed files with 5 additions and 4 deletions

View file

@ -67,7 +67,7 @@
default: false default: false
}, },
rowKey: { rowKey: {
type: Boolean, type: [Boolean, String],
default: false default: false
} }
}, },

View file

@ -236,8 +236,9 @@
default: 'dark' default: 'dark'
}, },
// #5380 :key 使 index // #5380 :key 使 index
// 4.1 String
rowKey: { rowKey: {
type: Boolean, type: [Boolean, String],
default: false default: false
}, },
// 4.0.0 // 4.0.0
@ -959,7 +960,7 @@
let data = deepCopy(this.data); let data = deepCopy(this.data);
data.forEach((row, index) => { data.forEach((row, index) => {
row._index = 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.children && row.children.length) {
if (row._showChildren) { if (row._showChildren) {
row._isShowChildren = row._showChildren; row._isShowChildren = row._showChildren;
@ -976,7 +977,7 @@
return data.children.map((row, index) => { return data.children.map((row, index) => {
const newRow = deepCopy(row); const newRow = deepCopy(row);
newRow._index = index; newRow._index = index;
newRow._rowKey = rowKey++; newRow._rowKey = (typeof this.rowKey) === 'string' ? row[this.rowKey] : rowKey++;
if (newRow._showChildren) { if (newRow._showChildren) {
newRow._isShowChildren = newRow._showChildren; newRow._isShowChildren = newRow._showChildren;
} else { } else {