mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-30 02:59:04 +08:00
update tree api:autoExpandParent, checkedKeys, onExpand
This commit is contained in:
parent
12331ea57c
commit
5374095604
@ -37,39 +37,6 @@ const generateData = (_level, _preKey, _tns) => {
|
||||
};
|
||||
generateData(z);
|
||||
|
||||
function loopData(data, callback) {
|
||||
const loop = (d, level = 0) => {
|
||||
d.forEach((item, index) => {
|
||||
const pos = `${level}-${index}`;
|
||||
if (item.children) {
|
||||
loop(item.children, pos);
|
||||
}
|
||||
callback(item, index, pos);
|
||||
});
|
||||
};
|
||||
loop(data);
|
||||
}
|
||||
|
||||
function getFilterExpandedKeys(data, expandedKeys) {
|
||||
const expandedPosArr = [];
|
||||
loopData(data, (item, index, pos) => {
|
||||
if (expandedKeys.indexOf(item.key) > -1) {
|
||||
expandedPosArr.push(pos);
|
||||
}
|
||||
});
|
||||
const filterExpandedKeys = [];
|
||||
loopData(data, (item, index, pos) => {
|
||||
expandedPosArr.forEach(p => {
|
||||
if ((pos.split('-').length < p.split('-').length
|
||||
&& p.indexOf(pos) === 0 || pos === p)
|
||||
&& filterExpandedKeys.indexOf(item.key) === -1) {
|
||||
filterExpandedKeys.push(item.key);
|
||||
}
|
||||
});
|
||||
});
|
||||
return filterExpandedKeys;
|
||||
}
|
||||
|
||||
const Demo = React.createClass({
|
||||
getDefaultProps() {
|
||||
return {
|
||||
@ -78,24 +45,20 @@ const Demo = React.createClass({
|
||||
},
|
||||
getInitialState() {
|
||||
return {
|
||||
expandedKeys: getFilterExpandedKeys(gData, ['0-0-0', '0-0-1']),
|
||||
expandedKeys: ['0-0-0', '0-0-1'],
|
||||
autoExpandParent: true,
|
||||
checkedKeys: ['0-0-0'],
|
||||
selectedKeys: [],
|
||||
};
|
||||
},
|
||||
onExpand(treeNode, expand, expandedKeys) {
|
||||
console.log('onExpand', expand, expandedKeys);
|
||||
const index = expandedKeys.indexOf(treeNode.props.eventKey);
|
||||
if (expand) {
|
||||
if (index > -1) {
|
||||
expandedKeys.splice(index, 1);
|
||||
}
|
||||
} else {
|
||||
if (index === -1) {
|
||||
expandedKeys.push(treeNode.props.eventKey);
|
||||
}
|
||||
}
|
||||
this.setState({ expandedKeys });
|
||||
onExpand(expandedKeys) {
|
||||
console.log('onExpand', arguments);
|
||||
// if not set autoExpandParent to false, if children expanded, parent can not collapse.
|
||||
// or, you can remove all expanded chilren keys.
|
||||
this.setState({
|
||||
expandedKeys,
|
||||
autoExpandParent: false,
|
||||
});
|
||||
},
|
||||
onCheck(checkedKeys) {
|
||||
this.setState({
|
||||
@ -119,8 +82,9 @@ const Demo = React.createClass({
|
||||
return <TreeNode key={item.key} title={item.key} />;
|
||||
});
|
||||
return (
|
||||
<Tree checkable multiple={this.props.multiple} defaultExpandAll
|
||||
<Tree checkable multiple={this.props.multiple}
|
||||
onExpand={this.onExpand} expandedKeys={this.state.expandedKeys}
|
||||
autoExpandParent={this.state.autoExpandParent}
|
||||
onCheck={this.onCheck} checkedKeys={this.state.checkedKeys}
|
||||
onSelect={this.onSelect} selectedKeys={this.state.selectedKeys}>
|
||||
{loop(gData)}
|
||||
|
@ -23,9 +23,6 @@ const Demo = React.createClass({
|
||||
defaultCheckedKeys: keys,
|
||||
};
|
||||
},
|
||||
onExpand(treeNode, expand, expandedKeys) {
|
||||
console.log('onExpand', expand, expandedKeys);
|
||||
},
|
||||
onSelect(info) {
|
||||
console.log('selected', info);
|
||||
},
|
||||
@ -36,7 +33,6 @@ const Demo = React.createClass({
|
||||
return (
|
||||
<Tree className="myCls" showLine multiple checkable
|
||||
defaultExpandedKeys={this.state.defaultExpandedKeys}
|
||||
onExpand={this.onExpand}
|
||||
defaultSelectedKeys={this.state.defaultSelectedKeys}
|
||||
defaultCheckedKeys={this.state.defaultCheckedKeys}
|
||||
onSelect={this.onSelect} onCheck={this.onCheck}>
|
||||
|
@ -20,16 +20,16 @@ english: Tree
|
||||
|defaultExpandAll | 默认展开所有树节点 | bool | false |
|
||||
|defaultExpandedKeys | 默认展开指定的树节点 | String[] | [] |
|
||||
|expandedKeys | (受控)展开指定的树节点 | String[] | [] |
|
||||
|autoExpandParent | 是否自动展开父节点 | bool | true |
|
||||
|defaultCheckedKeys | 默认选中复选框的树节点 | String[] | [] |
|
||||
|checkedKeys | (受控)选中复选框的树节点(注意:如果传入父节点key,则子节点自动选中;相应当子节点key都传入,父节点也自动选中) | String[] | [] |
|
||||
|halfCheckedKeys | 半选的树节点,用于想要在checkable下节点选择完全受控时(需要设置checkStrictly) | String[] | [] |
|
||||
|checkedKeys | (受控)选中复选框的树节点(注意: 父子节点有关联,如果传入父节点key,则子节点自动选中;相应当子节点key都传入,父节点也自动选中。当设置`checkable`和`checkStrictly`,它是一个有`checked``halfChecked`属性的对象,并且父子节点的选中与否不再关联 | String[]/{checked:Array<String>,halfChecked:Array<String>} | [] |
|
||||
|checkStrictly| checkable状态下节点选择完全受控(父子节点选中状态不再关联)| bool | false |
|
||||
|defaultSelectedKeys | 默认选中的树节点 | String[] | [] |
|
||||
|selectedKeys | (受控)设置选中的树节点 | String[] | - |
|
||||
|onExpand | 展开/收起节点时触发 | function(node, expanded, expandedKeys) | - |
|
||||
|onExpand | 展开/收起节点时触发 | function(expandedKeys, {expanded: bool, node}) | - |
|
||||
|onCheck | 点击复选框触发 | function(checkedKeys, e:{checked: bool, checkedNodes, node, event}) | - |
|
||||
|onSelect | 点击树节点触发 | function(selectedKeys, e:{selected: bool, selectedNodes, node, event}) | - |
|
||||
|filterTreeNode | filter some treeNodes as you need. it should return true | function(node) | - |
|
||||
|filterTreeNode | 按需筛选树节点(高亮),返回true | function(node) | - |
|
||||
|loadData | 异步加载数据 | function(node)| - |
|
||||
|onRightClick | 响应右键点击 | function({event,node}) | - |
|
||||
|draggable | 设置节点可拖拽(IE>8) | bool | false |
|
||||
|
@ -62,7 +62,7 @@
|
||||
"rc-tabs": "~5.8.0",
|
||||
"rc-time-picker": "~1.1.0",
|
||||
"rc-tooltip": "~3.3.2",
|
||||
"rc-tree": "~1.2.0",
|
||||
"rc-tree": "~1.3.0",
|
||||
"rc-tree-select": "~1.5.0",
|
||||
"rc-trigger": "~1.4.0",
|
||||
"rc-upload": "~1.10.0",
|
||||
|
Loading…
Reference in New Issue
Block a user