我正在使用 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
}