简体   繁体   English

如何将另一个页面的值更新到 Code.gs 数组列表中以传递到电子表格

[英]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));

See here :这里

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.

相关问题 将数组从Code.gs传递到Javascript Google App脚本 - Pass an Array from Code.gs to Javascript Google App Script 如何将变量从 Code.gs 传递到包含的脚本片段 - How to pass variable from Code.gs to included script snippet 如何将元素值变量从 Javascript html 文件传递到 google apps 脚本中的 code.gs 文件? - How to pass an element-value variable from Javascript html file to code.gs file in google apps script? Google Apps脚本,将两个(变量)2个“变量”或“数组”从code.gs传递给index.html / Javascript - Google apps script, pass (two) 2 “variables” or “array” from code.gs to index.html / Javascript 如何将 code.gs 中的变量添加到 Audio src? - How to Add variable from code.gs to Audio src? 使用 Code.gs 中的 javascript 从数组值动态 html 表 - Dynamic html Table from an array values using javascript in Code.gs 使用Google Apps脚本将对话框中输入字段的值返回到code.gs中的var - return value from input field in dialog box to var in code.gs using Google Apps Script 使用 html 对话框中输入字段的值使用 Google Apps 脚本在 code.gs 中进行 var - use value from input field in html dialog box to var in code.gs using Google Apps Script 从 code.gs Google App Script 内部获取变量值到 Javascript - Get Variable Value from inside code.gs Google App Script to Javascript 为什么 html 脚本没有从我的 code.gs 文件中获取列表 - Why is the html script not getting the list from my code.gs file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM