Google apps script 将Google脚本数组传递给Javascript函数(Google应用程序)
我理解为什么我的代码不起作用,但是我无法在网上找到解决方案。可能是一个简单的语法更正。代码如下: 代码.gs Index.htmlGoogle apps script 将Google脚本数组传递给Javascript函数(Google应用程序),google-apps-script,google-sheets,google-apps,Google Apps Script,Google Sheets,Google Apps,我理解为什么我的代码不起作用,但是我无法在网上找到解决方案。可能是一个简单的语法更正。代码如下: 代码.gs Index.html h1{ 宽度:100%; 溢出:隐藏; 背景色:#ABC; } #包装器{ 保证金:自动; 宽度:60%; 边框:3倍实心#000; 填充:10px; } Attendace差异跟踪器v1.0 差异日期: 员工编号: 主管: 函数findEmpID(){ var e=document.getElementById(“empName”); var strUser=e
h1{
宽度:100%;
溢出:隐藏;
背景色:#ABC;
}
#包装器{
保证金:自动;
宽度:60%;
边框:3倍实心#000;
填充:10px;
}
Attendace差异跟踪器v1.0
差异日期:
员工编号:
主管:
函数findEmpID(){
var e=document.getElementById(“empName”);
var strUser=e.options[e.selectedIndex].value;
document.getElementById(“empNumber”)
.innerHTML=;加载HTML后,您正试图使用scriptlet。看起来您正试图从下拉列表的onchange
属性触发scriptlet运行。我认为scriptlet将在首次加载页面时运行
我会改变这样的事情:
使用this
关键字将员工姓名传递给客户端findEmpID()
函数:
<h3>Select a name:</h3><select id='empName' onchange="findEmpID(this.value);">
<script>
function findEmpID(theName) {
google.script.run
.withSuccessHandler(enterName)
.getThisEmployeeID(theName);
};
function enterName(theReturnedName) {
//Put the name into the HTML Element
document.getElementById("empNumber").textContent = theReturnedName;
};
</script>
将名称传递给服务器函数:
<h3>Select a name:</h3><select id='empName' onchange="findEmpID(this.value);">
<script>
function findEmpID(theName) {
google.script.run
.withSuccessHandler(enterName)
.getThisEmployeeID(theName);
};
function enterName(theReturnedName) {
//Put the name into the HTML Element
document.getElementById("empNumber").textContent = theReturnedName;
};
</script>
我发现当你从googlescript
传递一个数组时,它并没有保持它的数组形式。相反,它变成了一个很长的字符串。我想如果我能分解这个字符串,我可以找到一个解决方案,但这似乎有点过分。
<script>
function findEmpID(theName) {
google.script.run
.withSuccessHandler(enterName)
.getThisEmployeeID(theName);
};
function enterName(theReturnedName) {
//Put the name into the HTML Element
document.getElementById("empNumber").textContent = theReturnedName;
};
</script>
function getThisEmployeeID(theName) {
//Get range of data
var arrayOfData = sheet.getRange(parameters).getValues();
//I don't know how the data is configured, but you'll need to match
//the name to the index number in the array, then get the ID
var employeeID = 'xyz';
return employeeID;
};