最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

使用for循环增量打印数组项

运维笔记admin15浏览0评论

使用for循环增量打印数组项

使用for循环增量打印数组项

我试图让一行注释掉的块在rowEcho上重复,具体取决于batchLength。用注释掉的“数组”替换整个函数按预期工作。这一切都发生在数据:[]对象中,我试图将值推送到谷歌工作表,以更新每行中的单元格,因为在响应数组中找到了记录。

感谢您的回复,但这些选项都没有按预期工作。我发布了更完整的代码以提供更好的范围,因为您可以看到我正在使用带有工作表API的preadsheets.values.batchUpdate请求尝试推送新数组但是使用batchUpdate方法必须按顺序知道整个新数据范围要覆盖,似乎没有办法更新列中的所有单元格,除非你有范围结束,因此我的下面尝试只要表格中有行就生成具有新数据的每个数组。肮脏我知道..

function changeSentValue(auth) {   
      var x = 0;
      for (var x = 0; x < rows.length; x++) {

        // put update spreadt sheet here
        console.log('updating to sent items..');

        const sheets = google.sheets({ version: 'v4', auth });

         sheets.spreadsheets.values.batchUpdate(request, function(err, response) {
            //var rows = response.data.values;

            if (err) {
              console.error(err);
              return;
            }
    ///here

          });

          var request = {
            spreadsheetId: 'xxxxxxxxxxxxxxxxxxxxx',
            resource: {
              valueInputOption: 'RAW',
              includeValuesInResponse: true,
              responseValueRenderOption: "UNFORMATTED_VALUE",

              // The new values to apply to the spreadsheet.
              data: [
                {
                  range: 'Sheet1!A2',
                  majorDimension: "ROWS",
               // values: [[5],[2],[5]]
               values: [

             function getLength ()  {
              var batchRows = response.data.values;
              var batchLength = 13/* batchRows.length */;
              var rowEcho = '[null,null,null,null,null,null,null,null,null,null,\"not\"],'; //col 11
            var y 
              for (y = 0; y < batchLength; y ++) {


                //write(rowEcho);
                 //console.log(rowEcho(y));
                 //these both dont work as expected
                }

                }
                /* [null,null,null,null,null,null,null,null,null,null,"notSent"],
                [null,null,null,null,null,null,null,null,null,null,"notSent"],
                [null,null,null,null,null,null,null,null,null,null,"notSent"],
                [null,null,null,null,null,null,null,null,null,null,"notSent"],
                [null,null,null,null,null,null,null,null,null,null,"notSent"],
                [null,null,null,null,null,null,null,null,null,null,"notSent"],
                [null,null,null,null,null,null,null,null,null,null,"notSent"],
                [null,null,null,null,null,null,null,null,null,null,"notSent"],
                [null,null,null,null,null,null,null,null,null,null,"notSent"],
                [null,null,null,null,null,null,null,null,null,null,"notSent"],
                [null,null,null,null,null,null,null,null,null,null,"notSent"],
                */
              ]


            }
          ],  // TODO: Update placeholder value.

          // TODO: Add desired properties to the request body.
        },

          auth: auth,
        }


      }


      }
回答如下:
function getLength() {
var batchLength = 8/* batchRows.length */;
var rowEcho = '[null,null,null,null,null,null,null,null,null,null,\"not\"],'; //col 11
var y
for (y = 0; y < batchLength; y++) {
//You forgot to print it
    console.log(rowEcho);
}
}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论