【发布时间】:2019-08-01 21:46:54
【问题描述】:
我正在尝试生成一个选择器,该选择器根据之前的选择器填充各种任务。我已经看到了使用 if/else if 块代码的简短方法,但是对于我的每个选择,我都有 20 多个可供选择的选项。
我尝试将选项放在电子表格内的各种工作表上并运行 if/else if 语句,以便下拉列表中填充来自与选择选项关联的工作表之一的任务。
<!--my selection i want to base the next selection options off of-->
<select id = 'reason'>
<option value="" disabled selected>Choose Reason</option>
<option value = 'prec'>PREC</option>
<option value = 'crh'>CRH</option>
<option value = 'bh'>BH</option>
<option value = 'ih'>IH</option>
<option value = 'rh'>RH</option>
</select>
<Label>Call Reason</Label>
</div>
<!-- function that generates tasks dynamically from a sheet -->
function getTasks(){
var ss= SpreadsheetApp.openByUrl(url);
var ws = ss.getSheetByName('PREC');
var list = ws.getRange(1,1).getDataRegion().getValues();
var options = {};
list.forEach(function(v){
options[v[0]]= null;
});
<!--essentially If someone chose "CRH" I would want it to open the sheet
with the CRH options -->
The way I wrote the loop didn't work.
function getTasks(){
var ss= SpreadsheetApp.openByUrl(url);
var options = {};
//basically added else ifs for each reason with the same code just dif
//sheet names
if (document.getElementById('reason')='prec'){
var ws = ss.getSheetByName('PREC');
var list = ws.getRange(1,1).getDataRegion().getValues();
list.forEach(function(v){
options[v[0]]= null;
}
});
return options
}
【问题讨论】:
标签: javascript html google-apps-script