How to prevent one-time click of one event when double-clicking extjs

I have a tree panel and for each node I have events with one click and double click. but with a double click, it also fires an event with one click. therefore, how to prevent a single click of a single click with a double click?

+5
source share
2 answers

Typically, using one-click and double-click events is considered bad practice and is very discouraged.

However, if you still want to do this, the only way to be able to distinguish between a single click and a double click is to artificially add this value by measuring the time between clicks.

, , . , . .

:

var singleClickTask = new Ext.util.DelayedTask(singleClickAction),  // our delayed task for single click
    singleClickDelay = 100; // delay in milliseconds

function onClick() {
    singleClickTask.delay(singleClickDelay);
}

function onDblClick() {
    // double click detected - trigger double click action
    doubleClickAction();
    // and don't forget to cancel single click task!
    singleClickTask.cancel();
}

function singleClickAction() {
    // something useful...
}

function doubleClickAction() {
    // something useful...
}


// setting event handlers on an Element
elem.on('click', onClick);
elem.on('dblclick', onDblClick);

:

  • , , singleClickDelay .
  • JavaScript 100% , .

, , , , .

+8

, , . , , .

onGridRowClick: function(view, record, item, index, e, eOpts) {
    if (record._task_in_progress) {
       return;
    }
    // Let the second click as part of the double click to be ignored
    record._task_in_progress = true;

    // Emulating async task here
    setTimeout(function() {
        record._task_in_progress = false;
    }, 1000);
}
+1

All Articles