需求:列表支持復(fù)選边坤,全選名扛,某些數(shù)據(jù)復(fù)選框禁用
按ant design vue官網(wǎng):
<template>
<a-table :rowSelection="rowSelection" :columns="columns" :dataSource="data">
<a slot="name" slot-scope="text">{{ text }}</a>
</a-table>
</template>
computed: {
rowSelection() {
const { selectedRowKeys } = this;
return {
onChange: (selectedRowKeys, selectedRows) => {
console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
},
getCheckboxProps: record => ({
props: {
disabled: record.name === 'Disabled User', // Column configuration not to be checked
name: record.name,
},
}),
};
},
},
問(wèn)題:全選時(shí),禁用復(fù)選框錯(cuò)亂茧痒。
image.png
解決:由于版本antd更新的原因肮韧,給數(shù)據(jù)加上key屬性
數(shù)據(jù):(注意key),若你的數(shù)據(jù)沒(méi)有key屬性,需對(duì)數(shù)據(jù)進(jìn)行處理,增加key屬性
const data = [
{
key: '1',
name: 'John Brown',
age: 32,
address: 'New York No. 1 Lake Park',
},
{
key: '2',
name: 'Jim Green',
age: 42,
address: 'London No. 1 Lake Park',
},
{
key: '3',
name: 'Joe Black',
age: 32,
address: 'Sidney No. 1 Lake Park',
},
{
key: '4',
name: 'Disabled User',
age: 99,
address: 'Sidney No. 1 Lake Park',
},
];