数据中没有key字段,鼠标不展开问题修复

This commit is contained in:
liushaozhen 2020-04-01 14:39:41 +08:00
parent ae9ad7fe86
commit f54853829a
4 changed files with 21 additions and 17 deletions

26
dist/demo.js vendored
View File

@ -80,7 +80,7 @@
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); }
var Demo1404 = __webpack_require__(606);var DemoArray = [{ "example": _react2['default'].createElement(Demo1404, null), "title": " 层级树大数据场景", "code": "/**\n* @title 层级树大数据场景\n* @parent 无限滚动 Infinite-scroll\n* @description\n* demo1404\n*/\nimport React, { Component } from \"react\";\nimport { Table, Button } from 'tinper-bee';\n\n\n\nimport BigData from \"bee-table/build/lib/bigData\";\nconst BigDataTable = BigData(Table);\nconst columns = [\n {\n title: '序号',\n dataIndex: 'index',\n width: '150',\n key: 'index',\n render: (text, record, index) => {\n return record.index ? record.index : index\n }\n },\n { title: \"用户名\", dataIndex: \"a\", key: \"a\", width: 580, className: \"rowClassName\" },\n { id: \"123\", title: \"性别\", dataIndex: \"b\", key: \"b\", width: 80 },\n { title: \"年龄\", dataIndex: \"c\", key: \"c\", width: 200 }\n];\n\nconst data = [...new Array(10)].map((e, i) => {\n const rs = { a: i + 'a', b: i + 'b', c: i + 'c', d: i + 'd', key: i };\n if (i % 3 == 0) {\n rs.b = '女';\n rs.children = [];\n for (let subi = 0; subi < 3; subi++) {\n rs.children.push({ a: i + subi + 'asub', b: i + subi + 'bsub', c: i + subi + 'csub', d: i + subi + 'dsub', key: i + `${subi} sub` });\n rs.children[subi].children = []\n for (let subj = 0; subj < 100; subj++) {\n rs.children[subi].children.push({ a: 333 + ' ' + subj, b: 333 + ' ' + subj, c: 333 + ' ' + subj, d: 333 + ' ' + subj, key: i + `${subj} sub1` });\n }\n }\n } else {\n rs.children = [];\n for (let subi = 0; subi < 3; subi++) {\n rs.children.push({ a: i + subi + 'asub', b: i + subi + 'bsub', c: i + subi + 'csub', d: i + subi + 'dsub', key: i + `${subi} sub` });\n }\n }\n return rs;\n})\n\nconst data2 = [...new Array(10000)].map((e, i) => {\n const rs = { a: i + 'a', b: i + 'b', c: i + 'c', d: i + 'd', key: i };\n if (i % 3 == 0) {\n rs.b = '女';\n }\n return rs;\n})\n\nclass Demo34 extends Component {\n constructor(props) {\n super(props);\n this.state = {\n data: data\n }\n }\n\n /**\n * expanded : 当前的状态\n * record : 当前行的数据\n */\n onExpand = (expanded, record) => {\n console.log('当前的状态---' + expanded, ' 当前行的数据---' , record);\n }\n handleClick = () => {\n this.setState({\n data: data2\n })\n }\n render () {\n return (\n <div>\n <Button onClick={this.handleClick} colors=\"secondary\" style={{ marginBottom: '8px' }}>改变数据源</Button>\n <BigDataTable\n columns={columns}\n data={this.state.data}\n parentNodeId='parent'\n scroll={{ y: 300 }}\n onExpand={this.onExpand}\n onRowClick={(record, index, indent) => {\n console.log('currentIndex--' + index);\n }}\n />\n </div>\n\n );\n }\n}\n\nexport default Demo34;", "desc": "" }];
var Demo1404 = __webpack_require__(606);var DemoArray = [{ "example": _react2['default'].createElement(Demo1404, null), "title": " 层级树大数据场景", "code": "/**\n* @title 层级树大数据场景\n* @parent 无限滚动 Infinite-scroll\n* @description\n* demo1404\n*/\nimport React, { Component } from \"react\";\nimport { Table, Button } from 'tinper-bee';\n\n\n\nimport BigData from \"bee-table/build/lib/bigData\";\nconst BigDataTable = BigData(Table);\nconst columns = [\n {\n title: '序号',\n dataIndex: 'index',\n width: '150',\n key: 'index',\n render: (text, record, index) => {\n return record.index ? record.index : index\n }\n },\n { title: \"用户名\", dataIndex: \"a\", key: \"a\", width: 580, className: \"rowClassName\" },\n { id: \"123\", title: \"性别\", dataIndex: \"b\", key: \"b\", width: 80 },\n { title: \"年龄\", dataIndex: \"c\", key: \"c\", width: 200 }\n];\n\nconst data = [...new Array(10)].map((e, i) => {\n const rs = { a: i + 'a', b: i + 'b', c: i + 'c', d: i + 'd', id: i };\n if (i % 3 == 0) {\n rs.b = '女';\n rs.children = [];\n for (let subi = 0; subi < 3; subi++) {\n rs.children.push({ a: i + subi + 'asub', b: i + subi + 'bsub', c: i + subi + 'csub', d: i + subi + 'dsub', id: i + `${subi} sub` });\n rs.children[subi].children = []\n for (let subj = 0; subj < 100; subj++) {\n rs.children[subi].children.push({ a: 333 + ' ' + subj, b: 333 + ' ' + subj, c: 333 + ' ' + subj, d: 333 + ' ' + subj, id: i + `${subj} sub1` });\n }\n }\n } else {\n rs.children = [];\n for (let subi = 0; subi < 3; subi++) {\n rs.children.push({ a: i + subi + 'asub', b: i + subi + 'bsub', c: i + subi + 'csub', d: i + subi + 'dsub', id: i + `${subi} sub` });\n }\n }\n return rs;\n})\n\nconst data2 = [...new Array(10000)].map((e, i) => {\n const rs = { a: i + 'a', b: i + 'b', c: i + 'c', d: i + 'd', id: i };\n if (i % 3 == 0) {\n rs.b = '女';\n }\n return rs;\n})\n\nclass Demo34 extends Component {\n constructor(props) {\n super(props);\n this.state = {\n data: data\n }\n }\n\n /**\n * expanded : 当前的状态\n * record : 当前行的数据\n */\n onExpand = (expanded, record) => {\n console.log('当前的状态---' + expanded, ' 当前行的数据---' , record);\n }\n handleClick = () => {\n this.setState({\n data: data2\n })\n }\n render () {\n return (\n <div>\n <Button onClick={this.handleClick} colors=\"secondary\" style={{ marginBottom: '8px' }}>改变数据源</Button>\n <BigDataTable\n columns={columns}\n data={this.state.data}\n scroll={{ y: 300 }}\n onExpand={this.onExpand}\n onRowClick={(record, index, indent) => {\n console.log('currentIndex--' + index);\n }}\n rowKey=\"id\"\n />\n </div>\n\n );\n }\n}\n\nexport default Demo34;", "desc": "" }];
var Demo = function (_Component) {
_inherits(Demo, _Component);
@ -87439,28 +87439,28 @@
}, { title: "用户名", dataIndex: "a", key: "a", width: 580, className: "rowClassName" }, { id: "123", title: "性别", dataIndex: "b", key: "b", width: 80 }, { title: "年龄", dataIndex: "c", key: "c", width: 200 }];
var data = [].concat(_toConsumableArray(new Array(10))).map(function (e, i) {
var rs = { a: i + 'a', b: i + 'b', c: i + 'c', d: i + 'd', key: i };
var rs = { a: i + 'a', b: i + 'b', c: i + 'c', d: i + 'd', id: i };
if (i % 3 == 0) {
rs.b = '女';
rs.children = [];
for (var subi = 0; subi < 3; subi++) {
rs.children.push({ a: i + subi + 'asub', b: i + subi + 'bsub', c: i + subi + 'csub', d: i + subi + 'dsub', key: i + (subi + " sub") });
rs.children.push({ a: i + subi + 'asub', b: i + subi + 'bsub', c: i + subi + 'csub', d: i + subi + 'dsub', id: i + (subi + " sub") });
rs.children[subi].children = [];
for (var subj = 0; subj < 100; subj++) {
rs.children[subi].children.push({ a: 333 + ' ' + subj, b: 333 + ' ' + subj, c: 333 + ' ' + subj, d: 333 + ' ' + subj, key: i + (subj + " sub1") });
rs.children[subi].children.push({ a: 333 + ' ' + subj, b: 333 + ' ' + subj, c: 333 + ' ' + subj, d: 333 + ' ' + subj, id: i + (subj + " sub1") });
}
}
} else {
rs.children = [];
for (var _subi = 0; _subi < 3; _subi++) {
rs.children.push({ a: i + _subi + 'asub', b: i + _subi + 'bsub', c: i + _subi + 'csub', d: i + _subi + 'dsub', key: i + (_subi + " sub") });
rs.children.push({ a: i + _subi + 'asub', b: i + _subi + 'bsub', c: i + _subi + 'csub', d: i + _subi + 'dsub', id: i + (_subi + " sub") });
}
}
return rs;
});
var data2 = [].concat(_toConsumableArray(new Array(10000))).map(function (e, i) {
var rs = { a: i + 'a', b: i + 'b', c: i + 'c', d: i + 'd', key: i };
var rs = { a: i + 'a', b: i + 'b', c: i + 'c', d: i + 'd', id: i };
if (i % 3 == 0) {
rs.b = '女';
}
@ -87509,12 +87509,12 @@
_react2["default"].createElement(BigDataTable, {
columns: columns,
data: this.state.data,
parentNodeId: "parent",
scroll: { y: 300 },
onExpand: this.onExpand,
onRowClick: function onRowClick(record, index, indent) {
console.log('currentIndex--' + index);
}
},
rowKey: "id"
})
);
};
@ -217314,9 +217314,9 @@
lazyLoad.preHeight = this.getSumHeight(0, startIndex);
lazyLoad.sufHeight = this.getSumHeight(endIndex, data.length);
}
console.log('*******data*****', data);
// console.log('*******data*****',data);
var dataSource = treeType && Array.isArray(treeData) && treeData.length > 0 ? treeData : data.slice(startIndex, endIndex);
console.log('*******dataSource*****', dataSource);
// console.log('*******dataSource*****',dataSource);
return _react2["default"].createElement(Table, _extends({}, this.props, {
data: dataSource,
lazyLoad: lazyLoad,
@ -217377,12 +217377,14 @@
if (Array.isArray(dataCopy)) {
for (var i = 0, l = dataCopy.length; i < l; i++) {
var _dataCopy$i = dataCopy[i],
key = _dataCopy$i.key,
children = _dataCopy$i.children,
props = _objectWithoutProperties(_dataCopy$i, ["key", "children"]),
props = _objectWithoutProperties(_dataCopy$i, ["children"]),
key = _this4.getRowKey(dataCopy[i], i),
dataCopyI = new Object(),
isLeaf = children && children.length > 0 ? false : true,
isExpanded = parentKey === null || expandedKeysSet.has(parentKey) ? expandedKeysSet.has(key) : false;
// console.log("getRowKey:: "+this.getRowKey(dataCopy[i],i))
dataCopyI = _extends(dataCopyI, {
key: key,

2
dist/demo.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "bee-table",
"version": "2.2.30-nc.2",
"version": "2.2.30-nc.3",
"description": "Table ui component for react",
"keywords": [
"react",

View File

@ -136,11 +136,13 @@ export default function bigData(Table) {
dataCopy = treeData;
if(Array.isArray(dataCopy)){
for (let i=0, l=dataCopy.length; i<l; i++) {
let { key, children, ...props } = dataCopy[i],
let { children, ...props } = dataCopy[i],
key = this.getRowKey(dataCopy[i],i),
dataCopyI = new Object(),
isLeaf = (children && children.length > 0) ? false : true,
//如果父节点是收起状态,则子节点的展开状态无意义。(一级节点或根节点直接判断自身状态即可)
isExpanded = (parentKey === null || expandedKeysSet.has(parentKey)) ? expandedKeysSet.has(key) : false;
// console.log("getRowKey:: "+this.getRowKey(dataCopy[i],i))
dataCopyI = Object.assign(dataCopyI,{
key,
isExpanded,
@ -562,9 +564,9 @@ export default function bigData(Table) {
lazyLoad.preHeight = this.getSumHeight(0, startIndex);
lazyLoad.sufHeight = this.getSumHeight(endIndex, data.length);
}
console.log('*******data*****',data);
// console.log('*******data*****',data);
const dataSource = (treeType && Array.isArray(treeData) && treeData.length > 0) ? treeData : data.slice(startIndex, endIndex);
console.log('*******dataSource*****',dataSource);
// console.log('*******dataSource*****',dataSource);
return (
<Table
{...this.props}