2014-09-10 196 views
0

對於我的代碼感到抱歉,我嘗試簡化本示例中的說明。 列表框的信息取決於我在其他列表框中選擇,但它不能工作。 抱歉我的英文不好。當我選擇另一個列表框時填充列表框

這裏我創建了我的表單;

function doGet(){ 
    var app = UiApp.createApplication().setTitle('Request Form'); 
    var flow = app.createFlowPanel().setStyleAttribute("textAlign", "center").setWidth("900px"); 

     var lreason = app.createLabel('Select reason :'); 
     var listreason= app.createListBox().setName("listreason").addItem("").addItem("SALUD").addItem("MOTIVO PERSONAL"); 
     var lfactor = app.createLabel('Select Factor :'); 
     var listfactor= app.createListBox().setName("listfactor").addItem("Select reason first").setId(listfactor); 


    var handlerr = app.createServerValueChangeHandler('factors'); 
    handlerr.addCallbackElement(flow); 
    listreason.addChangeHandler(handlerr); 
    var test1 = app.createLabel('nada'); 

    var gridd = app.createGrid(4,5); 

     gridd.setWidget(2,0,lreason) 
     .setWidget(2,1,listreason) 
     .setWidget(2,3,lfactor) 
     .setWidget(2,4,listfactor) 
     .setWidget(3,0,test1.setId('test1')); 

    flow.add(gridd); 
    app.add(flow); 
    return app; 
} 

//////////////////這裏創建填充功能的其他列表框

function factors(e){ 
var app=UiApp.getActiveApplication(); 

var var1=e.parameter.listreason; 
app.getElementById('test1').setText(var1); 

switch (var1) { 

    case "SALUD": 

var ss = SpreadsheetApp.openById('1pBayt_tB84E3wKhb-H5tVZJolx04F-Uq-Iom8O3KVHs'); 
var list = ss.getSheetByName('Salud'); 

var lastRow = list.getLastRow(); 

var templ = app.createListBox(); 
var values = list.getRange(2,1,lastRow-1,1).getValues(); 
for (var i in values){ 
templ.addItem(values[i][0].toString()); 
} 
app.getElementById('listfactor').addItem(templ); 

    break; 

    case "MOTIVO ESCOLAR": 

var ss = SpreadsheetApp.openById('1pBayt_tB84E3wKhb-H5tVZJolx04F-Uq-Iom8O3KVHs'); 
var list = ss.getSheetByName('MotivoEscolar'); 

var lastRow = list.getLastRow(); 
var templ = app.createListBox(); 

var values = list.getRange(2,1,lastRow-1,1).getValues(); 
for (var i in values){ 
templ.addItem(values[i][0].toString()); 
} 
app.getElementById('listfactor').addItem(templ); 
    break; 

    default: 

app.getElementById('test1').setText("empty"); 

    break 

} 
    return app; 
} 

回答

0

您使用此代碼是錯誤的(見註釋在代碼中):

for (var i in values){ 
templ.addItem(values[i][0].toString()); 
} 
app.getElementById('listfactor').addItem(templ);// you can not add a litBox as an item in another listBox 

你應該在循環後,其他只需添加一個項目...移動你這樣的代碼:

for (var i in values){ 
//templ.addItem(values[i][0].toString()); // this new list box is useless since you populate the existing one 
app.getElementById('listfactor').addItem(values[i][0].toString()); 
} 
相關問題