2

有人可以告诉我,如何遍历我自己使用 app.create[Widget] 命令创建的 UI 元素/小部件?例子:

function doGet(e) {
  var app = UiApp.createApplication();

  var panelMain = app.createVerticalPanel().setId("PanelMain");
  app.add(panelMain);


  var rb1 = app.createRadioButton().setId("Rb1");
  panelMain.add(rb1);

  var rb2 = app.createRadioButton().setId("Rb2");
  panelMain.add(rb1);


  *************************************************************
   AND NOW I WANT TO ITERATE THROUGH ALL CREATED ELEMENTS
    (MAINPANEL,RB1, RB2)

   Something like:
   var allElemts = app.getElements();
   for (var ele in allElements){
   Logger.log(ele.name);
   Logger.log(ele.type);
   ........
   }

  *******************************************************
  **** DO SOMEONE KNOW - HOW TO DO *************************
  ***************************************************************



  return app;
}

非常感谢

4

1 回答 1

0

因为没有像你想要的那样获取小部件上的元素的功能。

最好的选择是使用创建元素时使用的 ID,例如:

function doGet(e) {

  var app = UiApp.createApplication();
  var ids = [];

  var panelMain = app.createVerticalPanel().setId("PanelMain");
  app.add(panelMain);


  var rb1 = app.createRadioButton().setId("Rb1");
  panelMain.add(rb1);

  var rb2 = app.createRadioButton().setId("Rb2");
  panelMain.add(rb1);
  //store collection of ids from all widget
  ids.push(panelMain.getId());
  ids.push(rb1.getId());
  ids.push(rb2.getId());

  var allElemts = app.getElements();
  for (var id in ids){
    var element = ids[id];
    Logger.log(element.name);
    Logger.log(element.type);
  }
      return app;

}

于 2013-07-16T14:46:45.417 回答