简体   繁体   English

如何结合谷歌应用程序脚本processForm,withSuccessHandler和withUserObject

[英]how to combine google app script processForm, withSuccessHandler and withUserObject

So I'm following the documentation here: 所以我在这里关注文档:

https://developers.google.com/apps-script/html_service?hl=en#GoogleScriptAPI https://developers.google.com/apps-script/html_service?hl=zh_CN#GoogleScriptAPI

and it seems like I should be able to use processForm, withSuccessHandler and withUserObject in the same place, but I can't get it to work at the moment. 似乎我应该能够在同一位置使用processForm,withSuccessHandler和withUserObject,但目前无法使它正常工作。 Here's one attempt 这是一次尝试

<input name='submission'>
<input type='hidden' name='match' value ='<?= match?>'>
<input type='hidden' name='week' value ='<?= j?>'>
<input type='hidden' name='assignment' value ='<?= i?>'>
<input id='button' type='button' onclick='google.script.run.processForm(this.parentNode).withSuccessHandler(submissionReceived).withUserObject(this).getCurrentDate()'>

but this gives me the following error when the button is clicked: 但这在单击按钮时给我以下错误:

Cannot read property 'withSuccessHandler_m___' of undefined 无法读取未定义的属性“ withSuccessHandler_m___”

The following does work: 以下工作正常:

google.script.run.withSuccessHandler(submissionReceived).processForm(this.parentNode)

however I want the "submissionReceived" function to receive the local object so that I can make some local changes to reflect the fact that this particular button (of many) has been clicked. 但是,我希望“ submissionReceived”函数接收本地对象,以便我可以进行一些本地更改以反映该特定按钮(很多)已被单击的事实。 Basically this ordering: 基本上这个顺序:

google.script.run.processForm(this.parentNode).withSuccessHandler(submissionReceived)

fails with the same "Cannot read property 'withSuccessHandler_m___' of undefined " error, whether or not I am trying to pass an object to submissionReceived 失败,并显示相同的“无法读取未定义的属性'withSuccessHandler_m___'”错误,无论我是否尝试将对象传递给submittReceived

The following will run: 将运行以下命令:

google.script.run.withSuccessHandler(submissionReceived).withUserObject(this).processForm(this.parentNode)

but the single parameter that gets passed to submissionReceived is undefined 但是传递给submittingReceived的单个参数是未定义的

Any ideas about how to combine these three functions successfully in order to pass objects to the client side javascript functions on button clicks? 关于如何成功组合这三个功能以便在单击按钮时将对象传递给客户端javascript功能的任何想法?

I managed to get this to work with the following: 我设法使它与以下对象一起使用:

var r = google.script.run.withSuccessHandler(submissionReceived).withUserObject(this);r.processForm(this.parentNode); 

Seems like the successhandler needs to be set up first. 似乎需要先设置成功处理程序。 Also note that this passes two parameters to the submissionReceived function, the first of which is undefined and the second of which is the current local object, so the function definition is like this: 还要注意,这会将两个参数传递给submittingReceived函数,其中第一个是未定义的,而第二个是当前的本地对象,因此函数定义如下所示:

function submissionReceived(a,input) {

where a is undefinfed and input is the dom node corresponding to the input tag in which the script runs 其中a是未定义的,而input是与脚本在其中运行的input标签相对应的dom节点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM