GAS - 从 jquery 中获取值并将其传递给 code.gs 中的变量
GAS - take value from jquery and pass it over to a var in the code.gs
我正在尝试从 jquery 中获取电子邮件值并将其传递给 code.gs 中的 var。我目前拥有的代码是:
code.gs:
function getUser(){
user = Session.getActiveUser().getEmail();
return user;
}
function getUsername(){
Logger.log(emailSource);
Console.log(emailSource);
}
Jquery:
var user;
google.script.run.withSuccessHandler(getUserEmail).getUser();
function getUserEmail(userMail){
user = userMail;
$("#username").ready(function(){
$("#username").text(userMail);
});
}
function getUserEmail2code(emailSource){
var emailSource = $('#username').text();
$('#username').append(emailSource);
google.script.run.withSuccessHandler(getUserEmail2code).getUsername();
});
我的想法是获取该电子邮件地址,以便能够使用 google 工作表进行操作,并为每个工作表分配特定规则。
非常感谢
要将值从客户端 JavaScript 传递到服务器代码,您必须使用非常相似的工作流程,下面是一个带注释的示意图示例:
(注意勾选onclick附近使用的\'添加参数)
...
var someValue = $('#someDIV').val(); // get a value using JQuery and insert it in the onclick
...
$('#someOtherDiv').append('<br><input type="button" id="someID" onclick="someFunctiont(\''+someValue+'\')" value="this will call the function with parameter">');
...
function someFunction(parameter){
//call a server function here using Google.script.run
google.script.run.withSuccessHandler(otherClientFunctionToEventuallyDoSomething).serverFunction(parameter);
...
// in server .gs code :
function serverFunction(parameter){
// do something with the parameters...
}
我正在尝试从 jquery 中获取电子邮件值并将其传递给 code.gs 中的 var。我目前拥有的代码是:
code.gs:
function getUser(){
user = Session.getActiveUser().getEmail();
return user;
}
function getUsername(){
Logger.log(emailSource);
Console.log(emailSource);
}
Jquery:
var user;
google.script.run.withSuccessHandler(getUserEmail).getUser();
function getUserEmail(userMail){
user = userMail;
$("#username").ready(function(){
$("#username").text(userMail);
});
}
function getUserEmail2code(emailSource){
var emailSource = $('#username').text();
$('#username').append(emailSource);
google.script.run.withSuccessHandler(getUserEmail2code).getUsername();
});
我的想法是获取该电子邮件地址,以便能够使用 google 工作表进行操作,并为每个工作表分配特定规则。
非常感谢
要将值从客户端 JavaScript 传递到服务器代码,您必须使用非常相似的工作流程,下面是一个带注释的示意图示例:
(注意勾选onclick附近使用的\'添加参数)
...
var someValue = $('#someDIV').val(); // get a value using JQuery and insert it in the onclick
...
$('#someOtherDiv').append('<br><input type="button" id="someID" onclick="someFunctiont(\''+someValue+'\')" value="this will call the function with parameter">');
...
function someFunction(parameter){
//call a server function here using Google.script.run
google.script.run.withSuccessHandler(otherClientFunctionToEventuallyDoSomething).serverFunction(parameter);
...
// in server .gs code :
function serverFunction(parameter){
// do something with the parameters...
}