[英]How to update value from another page into Code.gs array list to be pass into spread sheet
My google sheet updating column in my spreadsheet as undefined.我的电子表格中的 Google 表格更新列未定义。 This is fine when I just pass the argument directly to the append function without using an array.
当我直接将参数传递给 append 函数而不使用数组时,这很好。
col1 col2
undefined undefined
What I'm expecting is.我所期待的是。
col1 col2
image1 image3
main Code.gs
主要代码.gs
var list1=[];
var url1='https://docs.google.com/spreadsheets/d/19ltZN-Gc6G6WJF9tJ-GRPjdXczlpp0IKWU1yJLszBxI/edit#gid=0';
var ss=SpreadsheetApp.openByUrl(url1);
var ws=ss.getSheetByName("Data");
function page1(id){
ws.appendRow(list1.push(id));
}
function page2(id){
list1.push([id]);
}
function lastPage(){
ws.appendRow([list1[0],list1[1]]);
}
page1.html
页面1.html
<?var url = getScriptUrl();?><a href='<?=url?>?page=page2'>
<img id="img4" onClick="imgClicked(this.alt)" alt="image4" src='https://lh3.googleusercontent.com/d/1gcuXbhSbVM9gSeffWgw_o1zHQ5PBvdaF=s220?authuser=0' width=200 height=200/>
</a>
</div>
<script>
function imgClicked(clicked){
var id = clicked
google.script.run.page1(id);
}
</script>
submit.html
提交.html
<?var url = getScriptUrl();?><a href='<?=url?>?page=page4'>
<img id="img4" onClick="imgClicked()" alt="image4" src='https://lh3.googleusercontent.com/d/1gcuXbhSbVM9gSeffWgw_o1zHQ5PBvdaF=s220?authuser=0' width=200 height=200/>
</a>
</div>
<script>
function imgClicked(){
google.script.run.lastPage();
}
</script>
Change改变
function page1(id){
ws.appendRow(list1.push(id));
}
to到
function page1(id){
list1.push(id);
ws.appendRow(list1);
}
You will understand the reason if you log如果你登录你就会明白原因
Logger.log(list1.push(id));
Return value The new length property of the object upon which the method was called.
返回值 调用方法的对象的新长度属性。
In other words, list1.push(id)
returns you the length of the array rather than its content.换句话说,
list1.push(id)
返回数组的长度而不是它的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.