2011-09-22 40 views
0

有没有办法在GAS的面板中访问小部件?在Google Apps脚本中的VerticalPanel中访问小部件?

喜欢的东西:

function clickHandler_(e) { 
    var app = UiApp.getActiveApplication(); 
    var panel = app.getElementById(e.parameter.whatever); // short-cutting here 
    for (var i=0; i<panel.widgets.length; i++) { 
    var widget = panel.widgets[i]; 
    // do something with them 
    } 
    return app; 
} 

回答

0

没有简单的东西是这样的。 你必须给所有添加的时候他们部件的ID,并将其保存的地方,所以你可以在以后检索。例如,面板上的标签:

function doGet(e) { 
    var app = UiApp.createApplication(); 
    ... 
    var panel = app.createXYZPanel().setId('mypanel'); 
    var IDs = ''; //list of child widgets on this panel 
    panel.add(widget.setId('id1')); 
    IDs += ',id1'; 
    panel.add(widget2.setId('id2')); 
    IDs += ',id2'; 
    //and so on... 
    panel.setTag(IDs); //save the IDs list as a tag on the panel 
    ... 
    return app; 
} 

//...later on a handler 
function handler(e) { 
    var app = UiApp.getActiveApplication(); 
    //the panel or a parent must be added as callback of the handler 
    var IDs = e.parameter.mypanel_tag.split(','); 
    for(var i = 1; i < IDs.length; ++i) { //skipping the 1st empty element 
    var widget = app.getElementById(IDs[i]); 
    //do something 
    } 
    return app; 
} 

顺便说一句,你可能知道,但你的代码有一个错误: 这不是UiApp.getElementById,但app.getElementById

+0

是啊,这是多了还是少了什么我落得这样做。谢谢!也为了赶上错字 - 只是在撰写这个问题时感到不快。 – Benj

相关问题