Google apps script Google应用程序脚本-在函数之间共享小部件
这是我第一次使用GoogleApps脚本,对于如何从多个功能访问小部件,我有点困惑 基本上,我希望有一个按钮来更新Google apps script Google应用程序脚本-在函数之间共享小部件,google-apps-script,Google Apps Script,这是我第一次使用GoogleApps脚本,对于如何从多个功能访问小部件,我有点困惑 基本上,我希望有一个按钮来更新标签小部件。因此,标签有一些默认文本,但在按下“更新”按钮后会更新以显示其他文本 从我所读到的内容来看,唯一可以传递到事件处理程序的是带有setName方法的对象。标签小部件没有此功能,因此如何从另一个处理程序函数更新我的doGet函数中小部件的值 以下是我想做什么(但无法开始工作)的想法: 我在互联网上搜索了几个小时,试图找到一个解决方案,但似乎没有找到答案。有什么建议吗?关于从对
标签
小部件。因此,标签有一些默认文本,但在按下“更新”按钮后会更新以显示其他文本
从我所读到的内容来看,唯一可以传递到事件处理程序的是带有setName
方法的对象。标签
小部件没有此功能,因此如何从另一个处理程序函数更新我的doGet
函数中小部件的值
以下是我想做什么(但无法开始工作)的想法:
我在互联网上搜索了几个小时,试图找到一个解决方案,但似乎没有找到答案。有什么建议吗?关于从对象名属性获取小部件的值,您提到的是获取小部件的值,而不是设置它。(在本例中,大写字母不是为了“呼喊”,而是为了引起注意:-) 标签的示例通常是无法读取值的小部件的示例 您正在寻找的是一种设置小部件值的方法:您必须通过其ID获取元素:请参见更新代码中的以下示例:
function doGet() {
var app = UiApp.createApplication();
// Create the label
var myLabel = app.createLabel('this is my label').setId('label');
app.add(myLabel)
// Create the update button
var updateButton = app.createButton('Update Label');
app.add(updateButton)
// Assign the update button handler
var updateButtonHandler = app.createServerHandler('updateValues');
updateButton.addClickHandler(updateButtonHandler);
return app;
}
function updateValues() {
var app = UiApp.getActiveApplication();
// Update the label
var label = app.getElementById('label').setText('This is my updated label');
return app;
}
天哪,谢谢你。我在任何地方都找不到这方面的文档。谷歌不允许你直接将标签对象传递到事件处理函数中,这太糟糕了。。。这似乎是一个更直观的过程。。。
function doGet() {
var app = UiApp.createApplication();
// Create the label
var myLabel = app.createLabel('this is my label').setId('label');
app.add(myLabel)
// Create the update button
var updateButton = app.createButton('Update Label');
app.add(updateButton)
// Assign the update button handler
var updateButtonHandler = app.createServerHandler('updateValues');
updateButton.addClickHandler(updateButtonHandler);
return app;
}
function updateValues() {
var app = UiApp.getActiveApplication();
// Update the label
var label = app.getElementById('label').setText('This is my updated label');
return app;
}