此应用程序脚本的想法是根据列表框 LbxJobTypes 中的选定项目填充列表框 LbxJobs。
我得到了一个未定义的 e.parameter.LbxJobType 值,这似乎阻止了 LbxJobs 的条件填充。
我通过硬编码(我设置 JobType=T300_JOB_TYPE)JobTypeValueHandler 函数成功地测试了处理程序(JobTypeValueHandler),并按预期填充了 LbxJobs 列表框。
检查 e.parameter.source 时,我确实得到了“LbxJobType”。列表框是在 GUI builder 中创建的。
var T200_JOB_TYPE = 1;
var T300_JOB_TYPE = 2;
function doGet() {
var app = UiApp.createApplication();
app.add(app.loadComponent("BasicCalculator"));
var Dischandler = app.createServerHandler('DiscClickHandler');
app.getElementById('chbxDiscl').addValueChangeHandler(Dischandler);
return app;
}
function DiscClickHandler(e) {
var app = UiApp.getActiveApplication();
var Discpanel = app.getElementById('FLpnlDisc');
BCalcSetup(app);
Discpanel.setVisible(false);
return app;
}
function BasicClickHandler(e) {
var app = UiApp.getActiveApplication();
return app;
}
function BCalcSetup(app){
var BCalcpanel = app.getElementById('APnlBCalc');
var lbxJobType = app.getElementById('LbxJobType');
var JobTpyehandler = app.createServerChangeHandler('JobTypeValueHandler');
var lbxJobs = app.getElementById('LbxJobs');
JobTpyehandler.addCallbackElement(lbxJobType);
lbxJobType.addChangeHandler(JobTpyehandler);
lbxJobType.addItem('Title 200');
lbxJobType.addItem('Title 300');
loadClassifications(lbxJobs,T200_JOB_TYPE);
BCalcpanel.setVisible(true);
}
function JobTypeValueHandler(e) {
var app = UiApp.getActiveApplication();
var JobType=T200_JOB_TYPE;
var lboxJobs=app.getElementById('LbxJobs');
if (e.parameter.LbxJobType=='Title 300'){JobType=T300_JOB_TYPE;}
loadClassifications(lboxJobs,JobType);
app.close();
return app;
}
function loadClassifications(lbox,JobType){
var spreadsheet = SpreadsheetApp.openById(SPREADSHEET_ID);
lbox.clear();
if (JobType==T300_JOB_TYPE){
var T3data =spreadsheet.getRangeByName('Title300Jobs').getValues();
for (var row1 = 1; row1 < T3data.length; row1++) {
lbox.addItem(T3data[row1]);
}
}else{
var T2data =spreadsheet.getRangeByName('Title200Jobs').getValues();
for (var row2 = 1; row2 < T2data.length; row2++) {
lbox.addItem(T2data[row2]);
}
}
}