2013-07-11 67 views
0

我有類似的問題到this question - 但我需要得到2 e.parameters的第一和第二個列表框,以填充第三個列表框的電子表格。第三個列表框從前2個列表框填充e.parameter [GAS]

vert正在被e.parameter讀取,但chan未定義,我不明白,因爲它是在第二個列表框中,但不是第三個完整的功能。

在這段代碼中是否有我監督過的東西?

var channelBox = app.createListBox().setId('channelBox').setName('channelBox').setWidth(152).setHeight(22); 
    var chanHandler = app.createServerChangeHandler('showChannelinfo'); 
    chanHandler.addCallbackElement(channelBox); 
    channelBox.addChangeHandler(chanHandler); 
    var chaArray = ['Select channel','--','Email','Phone','Chat']; for (var i=0;i<chaArray.length;++i) {channelBox.addItem(chaArray[i]);}; 

    var verticalBox = app.createListBox().setId('verticalBox').setName('verticalBox').setWidth(152).setHeight(22); 
    var vertHandler = app.createServerChangeHandler('showVerticalinfo'); 
    vertHandler.addCallbackElement(verticalBox); 
    verticalBox.addChangeHandler(vertHandler); 

function showChannelinfo(e){ 
    var app = UiApp.getActiveApplication(); 
    var itemSpreadsheetKey = 'ABC------------123'; 
    var openedSS = SpreadsheetApp.openById(itemSpreadsheetKey); 
    var sheetList3 = openedSS.getSheetByName("boolean3");//Vertical Lookup Sheet 
    var channelBox = app.getElementById('channelBox'); 
    var verticalBox = app.getElementById('verticalBox'); 
    var chan = e.parameter.channelBox; 

    if (chan == 'Phone') 
    { verticalBox.clear(); 
    var marketFilter = sheetList3.getRange('A1').setFormula('=iferror(filter(boolean2!A:D,boolean2!B:B=TRUE))');} 
    if (chan == 'Email') 
    { verticalBox.clear(); 
    var marketFilter = sheetList3.getRange('A1').setFormula('=iferror(filter(boolean2!A:D,boolean2!D:D=TRUE))');} 
    if (chan == 'Chat') 
    { verticalBox.clear(); 
    var marketFilter = sheetList3.getRange('A1').setFormula('=iferror(filter(boolean2!A:D,boolean2!C:C=TRUE))');} 

    var numItemList1 = sheetList3.getLastRow();//get the item array 
    var list1ItemArray = sheetList3.getRange(1,1,numItemList1).getValues();//Add the items in ListBox 
    for(var i=0; i<list1ItemArray.length; i++) 
    {verticalBox.addItem(list1ItemArray[i][0]);} 

    if (chan == '--') 
    {verticalBox.clear(); 
    var vertArray = ['Select vertical','Hardware','Apps','Ebooks','Movies','Music','Nik','Shopping','Places','Wallet','YouTube','BeatThatQuote']; 
    for (var i=0;i<vertArray.length;++i) {verticalBox.addItem(vertArray[i]);};} 

    return app 
}; 

function showVerticalinfo(e){ 
    var app = UiApp.getActiveApplication(); 
    var itemSpreadsheetKey = 'ABC------------123'; 
    var openedSS = SpreadsheetApp.openById(itemSpreadsheetKey); 
    var sheetList4 = openedSS.getSheetByName("boolean4");//Language Lookup Sheet 
    var channelBox = app.getElementById('channelBox'); 
    var verticalBox = app.getElementById('verticalBox'); 
    var langBox = app.getElementById('langBox'); 
    var chan = e.parameter.channelBox; 
    var vert = e.parameter.verticalBox; 

    langBox.clear(); 
    var langFilter = sheetList4.getRange('A1').setFormula('=iferror(filter(boolean!A:D,boolean!A:A="' + chan + '",boolean!B:B="' + vert + '",boolean!D:D=TRUE))'); 
    //**this returns as chan = undefined** 
    var numItemList2 = sheetList4.getLastRow();//get the item array 
    var list1ItemArray2 = sheetList4.getRange(1,3,numItemList2).getValues();//Add the items in ListBox 
    for(var i=0; i<list1ItemArray2.length; i++){langBox.addItem(list1ItemArray2[i][0]);} 

    if (chan == '--') 
    {langBox.clear(); 
    var langArray = ['Select language','Dutch','French','German','Italian','Portuguese', 'Russian','Spanish']; 
    for (var i=0;i<langArray.length;++i) {langBox.addItem(langArray[i]);};} 

    return app 
}; 

如果任何人都可以用他們的魔眼給我任何建議,將不勝感激!

回答

1

問題出在你的callbackElement上。 我建議你將這兩個列表框放到一個面板中,並將這個面板作爲回調元素添加到這兩個處理程序中。類似於

function doGet(){ 
    /* Your other code here */ 
    var panel = app.createVerticalPanel().setId('panel'); 

    var channelBox = app.createListBox().setId('channelBox').setName('channelBox').setWidth(152).setHeight(22); 
    var chanHandler = app.createServerChangeHandler('showChannelinfo'); 
    chanHandler.addCallbackElement(panel); /* Add panel as the callback element */ 
    channelBox.addChangeHandler(chanHandler); 
    var chaArray = ['Select channel','--','Email','Phone','Chat']; for (var i=0;i<chaArray.length;++i) {channelBox.addItem(chaArray[i]);}; 


    var verticalBox = app.createListBox().setId('verticalBox').setName('verticalBox').setWidth(152).setHeight(22); 
    var vertHandler = app.createServerChangeHandler('showVerticalinfo'); 
    vertHandler.addCallbackElement(panel); /* Add panel as the callback element */ 
    verticalBox.addChangeHandler(vertHandler); 

    panel.add(channelBox); 
    panel.add(verticalBox); 

    /* Your other UI Code here */ 

} 
+0

我簡直不敢相信它真的那麼簡單!我感謝你的超級快速回復,它的工作原理 - 有沒有解釋爲CallbackElement而不是列表框或者這是常態? @Srik – Julz