我正在使用 GAS 将数据写入电子表格,除了每次保存 TWICE 记录的部分外,一切都按预期工作。我不认为客户端或服务器功能会触发两次,所以它可能是我错过的其他东西。任何见解将不胜感激。谢谢!
客户端功能:
//save data
function savedata() {
var data = $('#dataSetter');
var startTime = data.find('#startTime').val();
var firstName = data.find('#firstName').val();
var lastName = data.find('#lastName').val();
var phone = data.find('#phone').val();
var email = data.find('#email').val();
var obj = $(this).parent();
var weekDate = getSuffix(obj.attr('id'));
weekDate = weekDate.replace('-', '/');
var year = getSuffix(obj.attr('class'));
var date = weekDate+'/'+year;
google.script.run.withSuccessHandler(dataSaved).setdata(office, firstName, lastName, phone, email, date, startTime);
google.script.run.withFailureHandler(onFailure).setdata(office, firstName, lastName, phone, email, date, startTime);
}
服务器功能:
//saves data
function setdata(office, firstName, lastName, phone, email, date, startTime) {
var dataSheet = dataBook.getSheets()[0];
var membersSheet = membersBook.getSheets()[0];
var membersLastRow = membersSheet.getLastRow();
var lastmemberID = membersSheet.getRange('A'+membersLastRow).getValue();
var newmemberID = memberID(lastmemberID);
membersSheet.appendRow([newmemberID, lastName, firstName, phone, email]);
}