Javascript Web应用程序脚本-如何从问题中提取值以用于搜索以填充另一个问题?
这是我的当前和附件 我已经能够使用函数getColumnIndexlabel成功地找到索引值,然后将该函数返回到函数getColumnValuesindex中,以提取该特定列中的所有行。我似乎无法使用自动完成问题id=courseCode输入课程代码的输入字段作为要在函数GetExpections中使用的搜索字符串;将HTML页面问题id=期望填充为多选问题Javascript Web应用程序脚本-如何从问题中提取值以用于搜索以填充另一个问题?,javascript,search,google-apps-script,Javascript,Search,Google Apps Script,这是我的当前和附件 我已经能够使用函数getColumnIndexlabel成功地找到索引值,然后将该函数返回到函数getColumnValuesindex中,以提取该特定列中的所有行。我似乎无法使用自动完成问题id=courseCode输入课程代码的输入字段作为要在函数GetExpections中使用的搜索字符串;将HTML页面问题id=期望填充为多选问题 function collectForm(){ var submission = {}; // gets you the
function collectForm(){
var submission = {};
// gets you the values for all id="specific_names"
submission.grade = document.getElementById("grade").value;
submission.courseCode = document.getElementById("courseCode").value;
var list = document.getElementsByClassName('selectedExpectations');
var selection = ' ';
for (i = 0; i < list.length; i++){
if (list[i].checked === true) {
selection += list[i].value + ", ";
}
}
submission.expectations = selection;
google.script.run.userClicked(submission);
}
如果我手动添加搜索字符串文本以返回列行,则它会起作用。我想将输入字段id=courseCode的前4个字符输入课程代码3个字母,后跟一个数字作为搜索字符串,以确定哪些选择选项将填充id=expectations问题
function collectForm(){
var submission = {};
// gets you the values for all id="specific_names"
submission.grade = document.getElementById("grade").value;
submission.courseCode = document.getElementById("courseCode").value;
var list = document.getElementsByClassName('selectedExpectations');
var selection = ' ';
for (i = 0; i < list.length; i++){
if (list[i].checked === true) {
selection += list[i].value + ", ";
}
}
submission.expectations = selection;
google.script.run.userClicked(submission);
}
我对在另一个函数中回调函数以及何时以及如何使用参数/条件传递函数有点困惑
我希望这是足够的信息来解决我的脚本错误。提前感谢您的关注。保重
添加了以下代码行,以便在多选课程期望问题中选择所有选项
function collectForm(){
var submission = {};
// gets you the values for all id="specific_names"
submission.grade = document.getElementById("grade").value;
submission.courseCode = document.getElementById("courseCode").value;
var list = document.getElementsByClassName('selectedExpectations');
var selection = ' ';
for (i = 0; i < list.length; i++){
if (list[i].checked === true) {
selection += list[i].value + ", ";
}
}
submission.expectations = selection;
google.script.run.userClicked(submission);
}
简言之
你需要这样的东西
/**
*
* @param {string} code
*/
function getExpectations2(code) {
var patt = new RegExp(code.slice(0, 5), 'i');
var data = SpreadsheetApp.openById(
'1evNXXgFITrdNwsSdGXmprgzti74AQy03dg0igP5nT0I'
)
.getSheetByName('expectations')
.getDataRange()
.getValues();
var colIndex = data[0].reduce(function(p, c, i) {
return patt.test(c) ? i : p;
}, -1);
return colIndex === -1
? []
: data
.slice(1)
.filter(function(row) {
return row[colIndex] !== '';
})
.map(function(row) {
return row[colIndex];
});
}
getExpectations2-按代码以列表形式返回列
您还必须更新您的ListExpections
自动完成课程代码在哪里
请在此处共享您的代码。请在问题中发布您的脚本。感谢您的详细回答@contributorpw-稍微改进,使问题成为页面第53行的多选选项。html添加多个。但是,它没有将多个选定的响应提交到表单,但其他数据确实在传输?@Maicol add submission.expectations=M.FormSelect.getInstancedocument.getElementById'expectations'.getSelectedValues.join';';把我的答案记为最好的。完整片段感谢您解决了这个问题。它工作得很好。我改变了,加入“;”;改为加入“\n”,以便更容易阅读多个选择。我希望我正确地把你的答案标记为最好的?小心点,我很感激。
const onAutocompleteCourseCode = courseCode => {
google.script.run
.withSuccessHandler(listExpectations)
.getExpectations2(courseCode);
};