Google apps script 遇到错误:TypeError:在对象泛型中找不到函数getValue
我对谷歌应用程序脚本非常陌生。我遇到了这个错误“TypeError:无法在object Generic中找到函数getValue”,我不知道为什么 代码如下:Google apps script 遇到错误:TypeError:在对象泛型中找不到函数getValue,google-apps-script,Google Apps Script,我对谷歌应用程序脚本非常陌生。我遇到了这个错误“TypeError:无法在object Generic中找到函数getValue”,我不知道为什么 代码如下: function doGet(e) { var app = UiApp.createApplication(); app.setTitle("My first application"); var vPanel = app.createVerticalPanel(); var hPanel3 = app.creat
function doGet(e) {
var app = UiApp.createApplication();
app.setTitle("My first application");
var vPanel = app.createVerticalPanel();
var hPanel3 = app.createHorizontalPanel();
hPanel3.add(app.createLabel("Text"));
var textArea = app.createTextArea().setId('theText').setName('theText');
//textArea.setName("textArea");
hPanel3.add(textArea);
vPanel.add(hPanel3);
var hPanel4 = app.createHorizontalPanel();
var button = app.createButton("Save");
var handler = app.createServerHandler('onClick');
handler.addCallbackElement(textArea);
button.addClickHandler(handler);
hPanel4.add(button);
vPanel.add(hPanel4);
var label = app.createLabel().setId('label').setText('tata');
//label.setName("label");
var hPanel5 = app.createHorizontalPanel();
hPanel5.add(label);
vPanel.add(hPanel5);
app.add(vPanel);
return app;
}
function onClick(e) {
var app = UiApp.getActiveApplication();
// ERROR occurs here when the button is clicked
var text = app.getElementById('theText').getValue();
Logger.log(text);
app.getElementById('label').setValue(e.parameter.textArea + ' toto');
//label.setText(textArea.getValue());
return app;
}
我已经更改了textArea的名称和id,但没有任何效果
谢谢你的帮助
改变
var text = app.getElementById('theText').getValue();
借
e是您的表单值您可以使用setName固定的名称来选择要在变量中获取的e参数如果您引用,则对于textArea没有
getValue()
这样的方法。正如Cartman回答的那样,您可以通过Callback元素获取值,该元素使用textArea的名称作为参数(除非您想setValue()
与其他内容一起使用,否则不需要ID)该类没有getValue
方法。它的值作为参数传递给处理程序。下面是一个演示其工作原理的示例
function doGet(e) {
var app = UiApp.createApplication();
var panel = app.createFlexTable();
panel.setWidth('100%');
var btn = app.createButton().setId('btn').setText('Click Me');
var textArea = app.createTextArea().setName('textArea').setValue('Text');
var handler = app.createServerHandler('onBtnClick');
handler.addCallbackElement(panel);
btn.addClickHandler(handler);
panel.setWidget(0, 0, btn);
panel.setWidget(1, 0, textArea);
app.add(panel);
return app;
}
function onBtnClick(e) {
var app = UiApp.getActiveApplication();
var btn = app.getElementById('btn');
var textAreaValue = e.parameter.textArea;
btn.setText(textAreaValue);
return app;
}
我认为它应该在TextArea中具有getValue或getText方法。我已经将addCallbackElement直接附加到文本区域,但它不起作用。现在,当我改用父面板时,它可以工作。谢谢你的帮助。
function doGet(e) {
var app = UiApp.createApplication();
var panel = app.createFlexTable();
panel.setWidth('100%');
var btn = app.createButton().setId('btn').setText('Click Me');
var textArea = app.createTextArea().setName('textArea').setValue('Text');
var handler = app.createServerHandler('onBtnClick');
handler.addCallbackElement(panel);
btn.addClickHandler(handler);
panel.setWidget(0, 0, btn);
panel.setWidget(1, 0, textArea);
app.add(panel);
return app;
}
function onBtnClick(e) {
var app = UiApp.getActiveApplication();
var btn = app.getElementById('btn');
var textAreaValue = e.parameter.textArea;
btn.setText(textAreaValue);
return app;
}