我到处搜索,找不到一个清楚的例子来说明如何使用 Googles UI Builder 和应用程序脚本。我不知道我错过了什么。我认为这应该很简单:v/ 是的,我已经阅读了所有 Google 的文档、观看了视频等 - 好几次 - 我找不到 GUIB (Google 的 UI Builder)和回调处理函数的组合。
编辑:有电子表格的例子 - 不是 GSites
我需要做的:
我想在谷歌网站页面上嵌入一个文本框和按钮来收集用户的搜索短语。我用单个流程面板、文本框和按钮构建了非常简单的 UI,但无论我做什么,都只能从 Logger.log() 返回“未定义” (参见下面的代码)。
有点咆哮:
我一直非常小心地命名,并用正确的名字称呼。我试过在 GUIB 中使用表单面板,但你只能在里面放一个小部件?!...而且提交按钮只会进入表单面板 - 嗯 - 我也不能把我的文本框放进去!? (那为什么还要麻烦表单面板 - 我不明白!......是的,我知道 doPost() 在提交时会自动被调用)。我希望小部件在一次使用后保持活动状态并且不会消失,所以表单面板/提交按钮可能无论如何都不起作用 - 或者不是正确的方法吗?
言归正传:
无论如何,我尝试将常规按钮和文本框放在带有以下代码的流程面板中......
编辑:我在这里删除了我的原始内容并重新发布了这个部分......
// Google Sites and UIBuilder (GUIB) - kgingeri (Karl)
// - this script is embedded in a GSite page via: Insert -> Apps Script Gadget.
//
// Withing GUIB I have defined:
// - a FlowPanel named 'pnlMain'
// - inside that a textBox named 'tbxQuery' and a button called 'btnSearch'
// - for btnSearch, I have defined (in the Events subsection) a callback function
// btnSearchHandler (see it below doGet() here. I expanded the [+] beside that
// and entered 'tbxQuery'
//
// the GUIB compnent tree looks like this...
//
// [-] testGui
// [-] pnlMain
// btnSearch
// tbxQuery
//
// btnSearch Event section looks something like this...
//
// Events
// On Mouse Clicks
// [X][btnSearchHandler][-]
// [tbxQuery ]<--'
// [Add Server]
// ...
//
// So...
// 1) when the page is opened, the doGet() function is called, showing the defined UI
// 2) when text is entered into the textBox and the button is clicked
// 3) the data from tbxQuery is **SUPPOSED TO BE** returned as e.parameter.tbxQuery
// in the function 'btnSearchHandler(e)' **BUT IS NOT** :v(
//
// (this functionality appears to work in a spreadsheet?! - weird?!)
//
// [ predefined function --- Google calls on page open ]
//
// ...this works 'as advertised' ;v)
//
function doGet(e) {
var app = UiApp.createApplication();
app.add(app.loadComponent("testGui")); // ...the title that shows in G/UIBuilder
return app;
}
//
// [ callBack for when a button is clicked ]
//
// ...I always get 'Resp: [Undefined]' returned in the View -> Logs menu?!
// ...I also tried to put 'pnlMain' in the Event [+] param, no go :v(
//
function btnSearchHandler(e) {
var resp = e.parameter.tbxQuery // ...the data I want in the textBox widget
Logger.log('Resp: [' + e.parameter.tbxQuery + ']');
// ...more code to come, once this works!
}
我还尝试在 doGet() 中添加代码以手动设置处理程序等,并且不使用 GUIB 事件设置,但也无济于事。
结论?
是什么赋予了?我是否必须手动编码 GUI 而不使用 GUIB?我知道这一次很简单,但如果我能做到这一点,我肯定会看到使用 GUIB 构建其他应用程序会更好!谁能给我或指出一个明确的例子?!
谢谢阅读!