0

我遇到了与这个问题类似的问题- 但是我需要获取第一个和第二个列表框的 2 个 e.parameters才能填充第三个列表框的电子表格。

e.parametervert正在读取 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
};

如果有人能用他们的魔眼给我任何建议,将不胜感激!

4

1 回答 1

1

问题出在您的回调元素上。我建议您将这两个列表框放在一个面板中,并将该面板作为回调元素添加到两个处理程序。就像是

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 */

}
于 2013-07-11T09:43:52.107 回答