如何区分日历约会的单击和双击?

时间:2019-06-06 07:13:01

标签: javascript sapui5 sap

我正在使用计划日历。我对日历约会具有单击功能,并且已通过双击自定义日历约会。 如果我双击约会,将同时触发单击和双击功能。如何解决此问题?

// this is the custom Calendar Appointment code.

sap.ui.define([
  "sap/ui/unified/CalendarAppointment"
],
function (
  CA
) {
  "use strict";
  var CalendarAppointment = CA.extend("com..........util.CalendarAppointment", {
    metadata: {
      events: {
        "rightpress": {},
        "dblclick": {}
      }
    }
  });
  CalendarAppointment.prototype.oncontextmenu = function (ovt) {
    this.fireRightpress();
  };
  CalendarAppointment.prototype.ondblclick = function (ovt) {
    this.fireDblclick();
  };
  return CalendarAppointment;
});

1 个答案:

答案 0 :(得分:0)

如果在很短的间隔内收到第二次点击,请使用超时取消简单的点击

// this is the custom Calendar Appointment code.

sap.ui.define([
  "sap/ui/unified/CalendarAppointment"
],
function (
  CA
) {
  "use strict";
  var CalendarAppointment = CA.extend("com..........util.CalendarAppointment", {
    metadata: {
      events: {
        "rightpress": {},
        "dblclick": {}
      }
    }
  });
  CalendarAppointment.prototype.oncontextmenu = function (ovt) {
    clearTimeout(this._singleClickTimeout)
    var DURATION = 250;
    this._singleClickTimeout = setTimeout(() => {
      this.fireRightpress();
    }, DURATION)
  };
  CalendarAppointment.prototype.ondblclick = function (ovt) {
    clearTimeout(this._singleClickTimeout)
    this.fireDblclick();
  };
  return CalendarAppointment;
});