0

我正在创建一个带有网格对象的 UI 实例。我在其中创建了一些项目,例如 5 个文本框。我通过回调元素传递网格,但我不知道如何使用 e.parameter 调用这些值。为什么这不起作用?

      function first()
        {
         var appheight = 360;
           var appwidth = 500;
            var defcolumns = 8;
           //Get the spreadsheet we are working on and Create a UI
          var ss = SpreadsheetApp.getActiveSpreadsheet();
          var app = UiApp.createApplication().setWidth(appwidth).setHeight(appheight).setTitle('Step 1:  Set Information');
        var mainGrid = app.createGrid(5, 1).setId("mainGrid"); 
        for(var r=0;r < 5;r++)
        {
         var columnname = app.createTextBox().setText(r.toString());
        mainGrid.setWidget(r, 0, columnname);
         }

      var steptwohandler =   app.createServerClickHandler("steptwo").addCallbackElement(mainGrid);
    var nextbutton = app.createButton().setId("btnnext").setText("Next ->").addClickHandler(steptwohandler);


}

function steptwo()
{
 var app =UiApp.getActiveApplication();
   //See how many rows exist already
    Logger.log(e.parameter.mainGrid);
  for(var r=0;r <=5; r++)
  {
    //should log 1-5 and the mainGrid object;
    Logger.log(r);
    Logger.log(e.parameter.mainGrid[r]);
  }

}

我已经看到了在 doctopus 脚本中执行类似操作的能力,但无法弄清楚他将如何解决它。

4

1 回答 1

0

您还必须在每个文本框上设置名称。请参阅下面的修改代码

 function first()
        {
         var appheight = 360;
           var appwidth = 500;
            var defcolumns = 8;
           //Get the spreadsheet we are working on and Create a UI
          var ss = SpreadsheetApp.getActiveSpreadsheet();
          var app = UiApp.createApplication().setWidth(appwidth).setHeight(appheight).setTitle('Step 1:  Set Information');
        var mainGrid = app.createGrid(5, 1).setId("mainGrid"); 
        for(var r=0;r < 5;r++)
        {
         /* Set a name for each text box */
         var columnname = app.createTextBox().setText(r.toString())
            .setName('columnname' + r.toString());
        mainGrid.setWidget(r, 0, columnname);
         }

      var steptwohandler =   app.createServerClickHandler("steptwo").addCallbackElement(mainGrid);
    var nextbutton = app.createButton().setId("btnnext").setText("Next ->").addClickHandler(steptwohandler);


}

/* Receive e as a parameter */
function steptwo(e)
{
 var app =UiApp.getActiveApplication();
   //See how many rows exist already
    Logger.log(e.parameter.mainGrid);
  for(var r=0;r <=5; r++)
  {
    //should log 1-5 and the mainGrid object;
    Logger.log(r);
    //Logger.log(e.parameter.mainGrid[r]);
    Logger.log(e.parameter['columnname' + r.toString()]);
  }

}
于 2013-08-01T05:02:16.697 回答