javascript - antd's Tree component, does it support drag and drop restrictions?
ringa_lee
ringa_lee 2017-05-19 10:32:01
0
1
880

When dragging the Tree component, I want to restrict the parent node from being dragged to the level of the child node, which means that only the child node can be dragged upwards. Can this be supported by antd?

ringa_lee
ringa_lee

ringa_lee

reply all (1)
洪涛

The final rendering only depends on what the data looks like. The change of the data is under your own control. Whether it is allowed or not is just a matter of whether the data changes.

For example, the following code,子节点只能放到第三个下面,不能放到第一个below (because this is my logic).

import * as React from 'react'; import {BaseComponent} from '../base'; import Tree from 'antd/lib/tree'; const TreeNode = Tree.TreeNode; import 'antd/lib/tree/style/index.css'; export interface HeaderProps { } export interface HeaderState { data: any } export class Header extends BaseComponent { state = { data: [ {name: '第一个', key: 'a'}, {name: '第二个', key: 'b', children: [ {name: '子节点', key: 'd'} ]}, {name: '第三个', key: 'c'} ] }; constructor(props:HeaderProps) { super(props); } onDragEnter(opt){ console.log(opt, 'x'); } onDrop(opt){ const fromNode = opt.dragNode.props.eventKey; const toNode = opt.node.props.eventKey; if(toNode !== 'c'){ return } this.state.data[2]['children'] = this.state.data[1]['children']; this.state.data[1]['children'] = []; this.setState({}); } loop(data){ return data.map( d => { if(d.children && d.children.length){ return {this.loop(d.children)} } else { return  } }) } render() { return (

{this.loop(this.state.data)}

) } }
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!