這段代碼出了什麼問題?當我登錄數組列表時,在sumbit
函數之前,它的確定(包含陣列中元素的期望內容和位置)。但是,當我通過e.parameter.arrayList
時,它不具有相同的值,也不是元素。如何解決這個問題?爲什麼嘗試從`e.parameter.variableName`方法恢復數組不工作?
function showList(folderID) {
var folder = DocsList.getFolderById(folderID);
var files = folder.getFiles();
var arrayList = [];
for (var file in files) {
file = files[file];
var thesesName = file.getName();
var thesesId = file.getId();
var thesesDoc = DocumentApp.openById(thesesId);
for (var child = 0; child < thesesDoc.getNumChildren(); child++){
var thesesFirstParagraph = thesesDoc.getChild(child);
var thesesType = thesesFirstParagraph.getText();
if (thesesType != ''){
var newArray = [thesesName, thesesType, thesesId];
arrayList.push(newArray);
break;
}
}
}
arrayList.sort();
var mydoc = SpreadsheetApp.getActiveSpreadsheet();
var app = UiApp.createApplication().setWidth(550).setHeight(450);
var panel = app.createVerticalPanel()
.setId('panel');
var label = app.createLabel("Choose your theses").setStyleAttribute("fontSize", 18);
app.add(label);
panel.add(app.createHidden('checkbox_total', arrayList.length));
panel.add(app.createHidden('arrayList', arrayList));
Logger.log(" arrayList before submit = " + arrayList);
for(var i = 0; i < arrayList.length; i++){
var checkbox = app.createCheckBox().setName('checkbox_isChecked_'+i).setText(arrayList[i][0]);
Logger.log("arrayList[i][0] = " + arrayList[i][0]);
Logger.log("arrayList[i] ====> " + arrayList[i]);
panel.add(checkbox);
}
var handler = app.createServerHandler('submit').addCallbackElement(panel);
panel.add(app.createButton('Submit', handler));
var scroll = app.createScrollPanel().setPixelSize(500, 400);
scroll.add(panel);
app.add(scroll);
mydoc.show(app);
}
function include(arr, obj) {
for(var i=0; i<arr.length; i++) {
if (arr[i] == obj) // if we find a match, return true
return true; }
return false; // if we got here, there was no match, so return false
}
function submit(e){
Logger.log(" arrayList = " + arrayList);
var arrayList = e.parameter.arrayList;
var numberOfItems = Number(e.parameter.checkbox_total);
var thesesArrays = [];
var usedThesesType = [];
var usedThesesName = [];
for(var i = 0; i < numberOfItems; i++){
if(e.parameter['checkbox_isChecked_'+i] == 'true'){
Logger.log(" arrayList inside for loop = " + arrayList);
Logger.log(" arrayList[i] = " + arrayList[i]);
thesesArrays.push(arrayList[i]);
usedThesesType.push(arrayList[i][1]);
Logger.log(" arrayList[i][1] = " + arrayList[i][1]);
usedThesesName.push(arrayList[i][0]);
Logger.log(" arrayList[i][0] = " + arrayList[i][0]);
}
}
var allThesesTypeArray = []; // To control Theses type apparence in the final doc
for (var i = 0; i < arrayList.length; i++) {
var thesesType = arrayList[i][1];
if (!(include(allThesesTypeArray, thesesType))){
allThesesTypeArray.push(thesesType); }
}
var targetDocId = userProperties.getProperty('targetDocId');
for (var i = 0; i < thesesArrays.length; i++) {
var thesesType = thesesArrays[i][1];
Logger.log(" thesesArrays = " + thesesArrays);
var thesesId = thesesArrays[i][2];
importTheses(targetDocId, thesesId, thesesType);
}
cleanNotUsedThesesTitles(targetDocId, allThesesTypeArray, usedThesesType);
if(userProperties.getProperty('atLeastOneTheseType') == 0){
Browser.msgBox('There was no theses inside your model. Check it!');
}
var joinAndInsert = userProperties.getProperty('joinAndInsert');
showURL(usedThesesName, joinAndInsert);
return UiApp.getActiveApplication().close();
}
因此,'submit(e)'函數是從與電子表格關聯的窗體觸發的?你有一個觸發器的功能名稱設置爲「提交」? –
你從'e'得到的值是多少? –