有人可以告诉我,如何迭代UI元素/小部件,这是由myselft使用app.create [Widget]命令创建的? 例如:
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;
}
非常感谢
答案 0 :(得分: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;
}