【发布时间】:2015-01-15 23:04:28
【问题描述】:
这段代码出了什么问题?当我记录数组列表时,在 sumbit 函数之前,它没问题(具有预期的内容和数组内元素的位置)。但是,当我通过e.parameter.arrayList得到它时,它没有相同的值,也不是元素。如何解决?
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得到什么值?
标签: javascript google-apps-script google-sheets