首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >react-konva中的onDblClick不工作

react-konva中的onDblClick不工作
EN

Stack Overflow用户
提问于 2017-07-26 01:47:09
回答 1查看 1.5K关注 0票数 1

我使用react-konva来渲染画布。我将onDblClick分配给一个组,我还将onClick,onDragEnd分配给这个组。在onDragEnd处理程序中,我向服务器发出了一个axios POST请求。每当我双击该组时,都会触发onDragEnd事件。有人知道这里的问题是什么吗?

以下是我的代码

代码语言:javascript
复制
handleMoving(){

    var thisElement = this.refs[this.state.key];

    this.setState({
        x: thisElement.x(),
        y: thisElement.y(),
        width: thisElement.getWidth(),
        height: thisElement.getHeight()
    });

    this.focus();
}

handleDoubleClick(){
    console.log('dbclick');
    this.focus();
    const stage = this.refs[this.state.key+'_wrapper'].getParent().getParent().getParent();
    const pos = this.refs[this.state.key].getAbsolutePosition();
    document.getElementById('newText').addEventListener('keydown',this.handleTextChange);
    document.getElementById('newTextWrapper').style.position = "absolute";
    document.getElementById('newTextWrapper').style.left = pos.x+"px";
    document.getElementById('newTextWrapper').style.top = pos.y+20+"px";
    document.getElementById('newText').style.width = this.refs[this.state.key+'_wrapper'].getWidth()+"px";
    document.getElementById('newTextWrapper').style.display = 'block';

}

syncToServer(){
    axios.post('/api/element/text/update',{
        uid:this.state.uid,
        key:this.state.key,
        content:this.state.content,
        stage:{
            x:this.state.x + this.refs[this.state.key].getParent().x(),
            y:this.state.y + this.refs[this.state.key].getParent().y(),
            width:this.state.width,
            height:this.state.height,
            fontSize:this.state.fontSize
        }
    }).then(function(response){
        console.log(response.data);
    });
}

render(){
    return (
        <Layer>
            <Group  onDblClick = {this.handleDoubleClick}
                    onClick = {this.handleClick}
                    onDragMove = {this.handleMoving}
                    onDragEnd = {this.syncToServer}
                    draggable = "true">
                <Rect   ref = {this.state.key + '_wrapper'}
                        x = {this.state.x}
                        y = {this.state.y}
                        width = {this.state.width}
                        height = {this.state.height}
                        visible = {false}
                        fill = 'lightgrey'
                        cornerRadius = {3}> 
                </Rect>
                <Text   ref = {this.state.key} 
                        x = {this.state.x} 
                        y = {this.state.y} 
                        fontSize = {this.state.fontSize}
                        fontFamily = {this.state.fontFamily}
                        text = {this.state.content}
                        fill = {this.state.color}
                        padding = {20}
                        >
                </Text>
            </Group>
        </Layer>
    );
}
EN

回答 1

Stack Overflow用户

发布于 2017-09-27 02:50:41

尝试使用ref的节点。

代码语言:javascript
复制
node.on('dblclick dbltap', () => {
  console.log('you clicked me!');
});
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45310344

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档