From 01468cdc541037b9ea40c809f62bcf143949605c Mon Sep 17 00:00:00 2001 From: afc163 Date: Fri, 1 Jan 2016 19:00:34 +0800 Subject: [PATCH] improve getDefaultSelection code implementation --- components/table/index.jsx | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/components/table/index.jsx b/components/table/index.jsx index 13dc5c6102..d851814730 100644 --- a/components/table/index.jsx +++ b/components/table/index.jsx @@ -67,19 +67,12 @@ let AntTable = React.createClass({ }, getDefaultSelection() { - let selectedRowKeys = []; - if (this.props.rowSelection && this.props.rowSelection.getCheckboxProps) { - let data = this.getCurrentPageData(); - data.filter((item) => { - if (this.props.rowSelection.getCheckboxProps) { - return this.props.rowSelection.getCheckboxProps(item).defaultChecked; - } - return true; - }).map((record, rowIndex) => { - selectedRowKeys.push(this.getRecordKey(record, rowIndex)); - }); + if (!this.props.rowSelection || !this.props.rowSelection.getCheckboxProps) { + return []; } - return selectedRowKeys; + return this.getCurrentPageData() + .filter(item => this.props.rowSelection.getCheckboxProps(item).defaultChecked) + .map((record, rowIndex) => this.getRecordKey(record, rowIndex)); }, componentWillReceiveProps(nextProps) { -- GitLab