0

我想使用下面的按钮将下拉列表中的选定项目添加到弹性表中。有人可以编辑我现有的代码以使其工作或向我展示我需要使用的处理程序吗?

我希望将项目放置在弹性表的第一列和第一行中。

链接到包含脚本的电子表格:这里

//Create button that adds items to flex table   
    var button = app.createButton('+');

PS:我是航空工程师,不是程序员。我还有很多东西要学。

4

1 回答 1

1

这是一些示例代码,展示了如何做你想做的事。基本上,创建一个将列表框作为回调元素的处理程序。然后,在处理函数中,使用 e.parameter.listBoxName 引用活动列表框条目以使用它。

function doGet() {
  var app = UiApp.createApplication();
  var listBox = app.createListBox();
  listBox.addItem("item 1").addItem("item 2").addItem("item 3").setName("myListBox");

  var handler = app.createServerHandler("buttonHandler");
  // pass the listbox into the handler function as a parameter
  handler.addCallbackElement(listBox);

  var table = app.createFlexTable().setId("myTable");

  var button = app.createButton("+", handler);
  app.add(listBox);
  app.add(button);
  app.add(table);
  return app;
}

function buttonHandler(e) {
  var app = UiApp.getActiveApplication();
  app.getElementById("myTable").insertRow(0).insertCell( 0, 0).setText( 0, 0, e.parameter.myListBox);
  return app;
}
于 2012-11-18T16:29:45.683 回答