当处理涉及鼠标的X,Y位置或不断更新的数据的任何时间的事件时,在T期间只使用一种模式对特定情况做出反应一次?
例如,如果我通过accept选项收听可放置的处理程序,则会不断执行accept函数以检查可丢弃性,但是如何在T周期内仅向用户弹出一次消息而不会轰击我的屏幕弹出消息?
$scope.layoutDropOptions = {
hoverClass: 'ui-state-highlight',
multiple: true,
tolerance: 'pointer',
accept: function (elem) {
var isAField = $(elem).hasClass("field");
var isFromSideBar = $(elem).parent().hasClass("fields");
var onTheSame = $(this).find('#' + $(elem).attr("id")).size() != 0;
var alreadyExists = $('.layoutContainer').find('#' + $(elem).attr("id")).size() != 0;
if (alreadyExists && isFromSideBar) {
// need to pop only once:
//toaster.pop('warning',
// UserMessages.formBuilder.duplicateField.title,
// UserMessages.formBuilder.duplicateField.body);
return false;
}
return isAField && !onTheSame ? true : false;
}
}
答案 0 :(得分:0)
我现在正在这样做,但我想也许有人可以想出一个更好的方法来获得积分?
var lastCall = 0;
$scope.layoutDropOptions = {
hoverClass: 'ui-state-highlight',
multiple: true,
tolerance: 'pointer',
accept: function (elem) {
var isAField = $(elem).hasClass("field");
var isFromSideBar = $(elem).parent().hasClass("fields");
var onTheSame = $(this).find('#' + $(elem).attr("id")).size() != 0;
var alreadyExists = $('.layoutContainer').find('#' + $(elem).attr("id")).size() != 0;
if (alreadyExists && isFromSideBar) {
if (new Date() - lastCall > 1000) {
lastCall = new Date();
toaster.pop('warning',
UserMessages.formBuilder.duplicateField.title,
UserMessages.formBuilder.duplicateField.body);
}
return false;
}
return isAField && !onTheSame ? true : false;
}
}