谷歌应用程序脚本 - 网络应用程序似乎没有做任何事情。 。 [英] google apps script - web app doesn't seem to do anything . .

查看:88
本文介绍了谷歌应用程序脚本 - 网络应用程序似乎没有做任何事情。 。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java开发人员,但是我为使用Google协作平台的非盈利组织创建了一个小型网站。我有一个表单,我希望有点动态,Google Apps脚本似乎是一个可行的选择。正如人们在学习新技术时经常发生的那样,我从教程/文档中复制并粘贴了以下代码。然后我发布了它,并将脚本小部件插入到网站上的一个页面并保存该页面。当我重新加载页面时,小部件的占位符就在那里,但没有任何反应 - 没有按钮,没有面板,什么都没有。当我从脚本编辑器运行它时,结果相同。我确定我错过了一些显而易见的东西,但我一直无法获得用户界面进行渲染。一个小方向将不胜感激。
在此先感谢!

pre $ 函数doGet(e){
Logger.log(执行doGet () 方法 。 。 。);

var app = UiApp.createApplication();
var aPanelRoot = app.createVerticalPanel();

var button = app.createButton('Click Me');
aPanelRoot.add(button);

var label = app.createLabel('按钮被点击');
label.setId('statusLabel');
aPanelRoot.add(label);

var handler = app.createServerHandler('myClickHandler');
handler.addCallbackElement(label);
button.addClickHandler(handler);

aPanelRoot.setVisible(true);
返回应用程序;
}

函数myClickHandler(e){
var app = UiApp.getActiveApplication();

var label = app.getElementById('statusLabel');
label.setVisible(true);

//app.close();
返回应用程序;
}


解决方案

doGet()函数中添加 aPanelRoot 到应用程序

  app.add(aPanelRoot)

also:by默认情况下,所有的小部件都是可见的,所以你可以删除所有 setVisible(true)语句,因为它们只有在你设置为 false 其他地方...

如果我可以添加最后一条评论,那么选择父窗口小部件通常是一个好主意 callbackElement 所以你不会冒险忘记添加元素,当你开始有很多元素时(所有的子元素都会自动包含在父元素中)。


I'm a Java developer but I did a small site for a non-profit group using Google Sites. I have a form I'd like to be somewhat dynamic and Google Apps Script seemed to be a viable option. As frequently happens when one is learning a new technology, I copied and pasted the code below from a tutorial/documentation. I then published it, and inserted the script widget into a page on the site and saved the page. When I reload the page, the "place holder" for the widget is there, but nothing happens - no buttons, no panel, nothing. Same results when I run it from the script editor. I'm sure I'm missing something obvious, but I haven't been able to get the UI to render at all. A little direction would be greatly appreciated. thanks in advance!

function doGet(e) {
  Logger.log("Executing the doGet() method . . .");

  var app = UiApp.createApplication();
  var aPanelRoot = app.createVerticalPanel();

  var button = app.createButton('Click Me');
  aPanelRoot.add(button);

  var label = app.createLabel('The button was clicked.');
  label.setId('statusLabel');
  aPanelRoot.add(label);

  var handler = app.createServerHandler('myClickHandler');
  handler.addCallbackElement(label);
  button.addClickHandler(handler);

  aPanelRoot.setVisible(true);
  return app;
}

function myClickHandler(e) {
  var app = UiApp.getActiveApplication();

  var label = app.getElementById('statusLabel');
  label.setVisible(true);

  //app.close();
  return app;
}

解决方案

It seems that you simply forgot to add aPanelRoot to the app in the doGet() function

app.add(aPanelRoot)

also : by default all widgets are visibles so you can remove all the setVisible(true) statements as they are only necessary if you set them to false somewhere else...

And if I may add a last comment, it's generally a good idea to choose the parent widget as callbackElement so you don't risk to forget to add elements when you begin to have lots of them (all children are automatically included in the parent) .

这篇关于谷歌应用程序脚本 - 网络应用程序似乎没有做任何事情。 。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆