Skip to content

Is any call monitor.getItemType() return null at the beginDrag function call #698

@lcoder

Description

@lcoder

what I'm code:

import ItemTypes from 'macro/ItemTypes' ;

const dragSource = {
    beginDrag( props , monitor ){
        let itemType = monitor.getItemType() ;
        console.log( itemType ) ;  // always return null whatever I drag any dragsource
        // cell 拖拽
        if( itemType == ItemTypes.EXIST_CARD ){
            let position = props.position ,
                arrayIndex = props.arrayIndex ;
            return {
                type: 'reRank' ,
                position ,
                arrayIndex
            }
        }else if( itemType == ItemTypes.ROWCARD ){
            return {} ;
        }else{
            console.warn( '未定义拖拽源' , itemType ) ;
            return {} ;
        }
    } ,
    canDrag( props , monitor ){
        let itemType = monitor.getItemType() ;
        let item = monitor.getItem() ;
        console.log( itemType )
        if( props.obj ){                // DragInner已经绑定了一个对象 ( 表单控件 描述对象 )
            return true ;
        }else{
            return false ;
        }
    }
}
export default dragSource ;

At beginDrag function console.log( itemType ) always return null .what evet I drag EXIST_CARD or ROWCARD dragSource .

DragSource:

@DragSource( ItemTypes.EXIST_CARD , dragSource , ( connect , monitor )=>{
    return {
        connectDragSource: connect.dragSource() 
    }
} )
export default class DragInner extends Component {
    static propTypes = {
        connectDropTarget: PropTypes.func.isRequired
    }
    constructor(props) {
      // ...
    }
    render() {
       // ...
        return connectDragSource(
            connectDropTarget(
              <div className={className} style={{
                    minHeight: '30px' ,
                    backgroundColor ,
                }} onClick={this.handleClick}>
                { /*hasDropped && <span>dropped {hasDroppedOnChild && ' on child'}</span>*/ }
                { modelToReact( obj ) }
              </div>
            )
        ) ;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions