0

我正在使用 doGet() 示例代码从隐藏对象传递值。它适用于添加列的第一种情况,但在 delcolumn 上,我的记录器中出现 NaN/Undefined。试图找出原因,因为代码看起来与 Google 教程相同。

function onOpen() {

    var ss = SpreadsheetApp.getActiveSpreadsheet();
   var menuEntries = [ {name: "BuildUI", functionName: "BuildUi"} ];
  ss.addMenu("BuildUI", menuEntries);

}


function BuildUi() 
  {



 var appheight =360
  var app = UiApp.createApplication().setWidth(500).setHeight(appheight).setTitle('Step 1:  PickBoxes');
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var panel = app.createVerticalPanel().setId("settingsPanel");

  var headerpanel = app.createVerticalPanel().setId("headerPanel").setStyleAttribute("background", "silver").setWidth(500);
  var columnPanel = app.createVerticalPanel();
  var mainGrid = app.createGrid(5, 1).setId("mainGrid");
  var scroller =app.createScrollPanel();
  var hidinstallcolumns =app.createTextBox().setId("hidinstallcolumns").setName("hidinstallcolumns").setValue("1");

  var columnGrid =app.createGrid(1,1).setId("columnGrid");
  var headerlabel = app.createLabel("Headerlabel").setStyleAttribute("background", "silver").setWidth(500);
  headerlabel.setText('Please Add Text')

  //Set up Selection for columns
  var columnspanel = app.createHorizontalPanel().setId("columnspanel");
  var columnname = app.createTextBox().setText("Name");
  var columntype = app.createListBox();
  var columnlabel = app.createLabel("1");
  var columndelhandler = app.createServerClickHandler("columndel").addCallbackElement(hidinstallcolumns);

  var columndelbutton = app.createButton().setText("X").addClickHandler(columndelhandler);  
  columntype.addItem("1");
  columntype.addItem("2");
  columntype.addItem("3");
  columntype.addItem("4");  
  columnspanel.add(columnlabel);

  columnspanel.add(columnname);
  columnspanel.add(columntype);
 columnspanel.add(columndelbutton);
  //    
  var addcolumnspanel = app.createHorizontalPanel().setId("addcolumnspanel");
  var addbuttonhandler = app.createServerClickHandler("addcolumn").addCallbackElement(hidinstallcolumns);

  var addbutton = app.createButton().setId("btnaddcolumn").setText("Add another column").addClickHandler(addbuttonhandler);  

  addcolumnspanel.add(addbutton);   
  columnGrid.setWidget(0, 0, columnspanel);
  scroller.add(columnGrid);
  scroller.setHeight(appheight-80);
  mainGrid.setWidget(0, 0, headerlabel);
  mainGrid.setWidget(1, 0, scroller);
  mainGrid.setWidget(2, 0, addcolumnspanel);

  panel.add(mainGrid);

  app.add(panel);
  ss.show(app);
    Logger.log("Fully DoNe");
  return app;
}


 function addcolumn(e) {

  var app =UiApp.getActiveApplication();
   var mybutton = app.getElementById("btnaddcolumn");
   mybutton.setEnabled(false);
   var columnrownumbers =  parseFloat(e.parameter.hidinstallcolumns);
   Logger.log("printcolumns");
   Logger.log(columnrownumbers);
   columnrownumbers++;
   Logger.log(columnrownumbers);
   var mytarg = app.getElementById("hidinstallcolumns");
   mytarg.setText(columnrownumbers.toString());
  var delhidstr = "del" + columnrownumbers.toString();
  Logger.log(delhidstr); 
   var columnnum =app.createHidden(delhidstr.toString(),columnrownumbers).setId("columnnum");
  var columngrid = app.getElementById('columnGrid');
  var columnspanel = app.createHorizontalPanel().setId("columnspanel");
  var columnname = app.createTextBox().setText("Name");
  var columntype = app.createListBox();
  var columnlabel = app.createLabel(columnrownumbers);
  app.add(columnnum);
  var columndelhandler = app.createServerHandler("columndel").addCallbackElement(columnnum);
  var columndelbutton = app.createButton().setText("X").addClickHandler(columndelhandler);  
  columntype.addItem("1");
  columntype.addItem("2");
  columntype.addItem("3");
  columntype.addItem("4");
   columnspanel.add(columnlabel);
  columnspanel.add(columnname);
  columnspanel.add(columntype); 
  columnspanel.add(columndelbutton);
  columngrid.resize(columnrownumbers, 1); 
  var location = columnrownumbers;
  location = location -1;
  columngrid.setWidget(location ,0,columnspanel);
  mybutton.setEnabled(true);
  return app; 


}

  function columndel(eventInfo)
{
  var app =UiApp.getActiveApplication();
  Logger.log(eventInfo.parameter.columnnum); //Keeps getting undefined
  Logger.log(parseFloat(eventInfo.parameter.columnnum)); //Keeps getting NaN
}
4

2 回答 2

0

var columnnum没有.setName()

于 2013-07-22T05:10:57.280 回答
0

当您使用创建隐藏小部件时,接受的答案不正确

   var columnnum =app.createHidden(delhidstr.toString(),columnrownumbers).setId("columnnum");

您隐含地给了它一个名称(请参阅此处的文档),因为第一个字符串参数实际上是小部件的名称。

所以错误是你试图使用错误的名称而不是没有名称的小部件来获取值。

于 2013-11-03T14:04:32.940 回答