只需按照你自己的答案建议:
你也许可以把它由具有转换表的地方,从他们的ID获取部件名称工作。
例如,你可以定义:
ScriptProperties.setProperties({'widgetID1':'Name1','widgetID2':'name2'},true)
然后
widgetvalue = e.parameter[ScriptProperties.getProperty(e.parameter.source)]
我没有测试此代码,但它似乎是合乎逻辑;-),告诉我,如果它没有(我现在没有时间测试它)
编辑:按预期工作,这里是一个test sheet来显示结果,测试代码如下。
function Test(){
var app = UiApp.createApplication().setTitle('test');
app.add(app.createLabel('Type anything in upper textBox and then move your mouse over it...'))
var p = app.createVerticalPanel()
var txt1 = app.createTextBox().setId('txt1').setName('Name1').setValue('value in TextBox1')
var txt2 = app.createTextBox().setId('txt2').setName('Name2').setValue('waiting to mouseOver textBox1')
p.add(txt1).add(txt2)
app.add(p)
var handler = app.createServerHandler('mouseOver').addCallbackElement(p);
txt1.addMouseOverHandler(handler);
ScriptProperties.setProperties({'txt1':'Name1','txt2':'Name2'},true);//save the name, only txt1 will be used here
var ss=SpreadsheetApp.getActiveSpreadsheet()
ss.show(app)
}
function mouseOver(e) {
var app = UiApp.getActiveApplication();
var widget = app.getElementById(e.parameter.source);
var widgetValue = e.parameter[ScriptProperties.getProperty(e.parameter.source)]; // ScriptProperties knows the Widget's name
app.getElementById('txt2').setValue(widgetValue) ;// Use the other widget to show result
return app;
}
聪明,但这种方法实际上并不实际工作。看来我需要传入的实际名称。 – Eclipzer