因此,作为实习生,我正在做一个项目,使用Bugsnag来捕捉他们的web应用程序中的错误。有一个错误,我试图修复,我不能复制。在我们所有使用该产品的客户中,只有2个人受到影响。我没有编写这段代码,我只是试图修复其中的错误。错误是TypeError·Uncaught TypeError: Cannot set property 'selected' of undefined,它在第二行的这个函数中。
function selectInstaller(installer) {
installers[installer.id].selected = true;
selectedInstaller[installer.id] = installer;
}应该发生的情况是,存在一个个人列表,用户可以选择一个人在日历上显示该个人的事件。一旦用户被选中,这个函数就会被调用。
function handleSelectInstaller(event) {
var $btn = $(this);
var $li = $btn.closest('li');
$li.toggleClass('active');
var installerAttributes = $btn.closest('li').data();
if($li.hasClass('active')) {
selectInstaller(installerAttributes);
fetchInstallerCalendar();
} else {
previousInstallerCount = Object.keys(selectedInstaller).length;
unselectInstaller(installerAttributes);
syncView();
}
}如您所见,handleSelectInstaller函数然后调用selectInstaller函数,然后发生错误。就像我说的,这是一个罕见的错误发生,我看不出重现错误。我想,也许那个特定人的数据库有问题,但我的经理看了看,他说它看上去是对的。他还尝试登录到用户的帐户,并试图以这种方式复制它,但这并没有给他带来任何问题(因此他无法在他的计算机上复制)。但是Bugsnag在用户登录到他们的计算机上时仍在报告这个问题。对于如何重现这个错误,我有什么想法,这样我就可以解决问题了吗?还是我完全控制不了?
编辑:以下是加载页面时所调用的内容。最后一个函数将自动选择登录的用户。然后,当用户(安装程序)选择或取消其名称时,将调用handleSelectInstaller函数。堆栈跟踪显示我们进入了handleSelectInstaller函数。
function init(options) {
var options = options || {};
baseUrl = serverpath + "v1.0/calendar_events";
selector = options.selector || '#calendar';
colors = {
default: '#59595C',
disabled: '#ff9f89'
};
dateFormat = 'YYYY-MM-DD';
type = $(selector).data('type');
installers = {};
installerArray = [];
selectedInstaller = {};
cache = {};
cacheCalendar = {};
currentMonth = {start: null, end: null}
standardInstallerObject = {jobs: {}, daysOfWeekDisabled: {}, time_off: {}, color:null}
previousInstallerCount = 0;
setup();
}
function setup() {
setupListeners();
setupDatePickers();
$('.installer-name').text('Select Installer');
syncEventTypes();
syncJobStatuses();
fetchInstallers(setupCalendar);
}
function fetchInstallers(callback) {
$.ajax({
url: serverpath + 'v1.0/users?role=installers',
type: "GET",
dataType: 'json'
}).done(function(response) {
loadInstallers(response);
if(typeof callback === 'function') callback();
})
.fail(function(xhr) {
handleError(xhr);
$('#calendar-loading-indicator').fadeOut();
})
.always(function() { });
}
function loadInstallers(response) {
for(var i in response) {
var installer = response[i];
var id = installer.id;
//need to extend / copy object since the object would be stored by reference not by value
var copiedObject = $.extend(true, {}, standardInstallerObject);
var copiedObjectCalendar = $.extend(true, {}, standardInstallerObject);
cache[id] = copiedObject;
cacheCalendar[id] = copiedObjectCalendar;
if(installers[id]) continue;
installers[id] = installer;
installerArray.push(installers[id]);
}
if(type == 'installer') {
var installer = installers[$.User.id()];
selectInstaller(installer);
$('.installer-pick-list li[data-id="'+ $.User.id() +'"]').addClass('active');
}
}发布于 2017-05-05 16:09:25
您在使用ajax调用吗?也许可以使用setTimeout模拟一个长时间的ajax调用,看看是否有相同的错误。因此,用一个setTimeout调用包装ajax调用,并将其设置为喜欢4000或类似的东西。这里有一个很好的例子来说明我在说什么。using SetTimeout with Ajax calls
setTimeout(function(){checkData()}, 5000);
function checkData(){
$.ajax({
//
});
}因为它已经运行了功能,用户可以先选择一个安装程序,这样就可以完成类似的操作。
为公众
$.ajax({
url: //something
type: "GET",
dataType: 'json'
}).done(function(response) {
loadInstallers(response);
$.publish('Installer.set_installer_info');
if(typeof callback === 'function') callback();
})
});为订阅者
$.subscribe('Installer.set_installer_info', function() {
$('body').on('click', '.installer-calendar-container .installer-pick-list .selectable', handleSelectInstaller);
});https://stackoverflow.com/questions/43767463
复制相似问题