[英]call google app script user defined method on JavaScript event
我在 html 中有很多錨標簽,屬性data-action="someAction"
。
我想從 1 JavaScript 點擊事件中調用這些操作,如下所示:
但是這個測試拋出錯誤
Uncaught TypeError: google.script.run.withSuccessHandler(...).withFailureHandler(...).withUserObject(...).action is not a function
更新:
正如我檢查過的那樣, console.log(action)
是一個string
類型,有沒有辦法讓它成為 Google App Script 的方法,以便我的下面的腳本可以工作?
我的腳本:
$('.icon-action').on("click", function() {
let action = $(this).attr("data-action");
google.script.run
.withSuccessHandler(
function(returnSuccess, element) {
// return success
})
.withFailureHandler(
function(msg, element) {
// return error
})
.withUserObject(this)
.action();
});
在Oleg Valter的幫助和建議下,我解決了這個問題。 對於未來的用戶,我在這里發布我的工作解決方案。 請參考此評論 - 在 JavaScript 事件上調用谷歌應用腳本用戶定義方法
$('.icon-action').on("click", function() {
let action = $(this).attr("data-action");
google.script.run
.withSuccessHandler(
function(returnSuccess, element) {
// return success
})
.withFailureHandler(
function(msg, element) {
// return error
})
.withUserObject(this)[action]();
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.