javascript - 使用 for 循环增量打印数组项
问题描述
我试图让一行注释掉的块在 rowEcho 上重复,具体取决于batchLength。用注释掉的“数组”替换整个函数按预期工作。这一切都发生在一个 data:[] 对象中,我试图将这些值推送到谷歌表格,以更新每一行中的一个单元格,以便在响应数组中找到尽可能多的行。
感谢您的回复,但这些选项都没有按预期工作。我发布了更完整的代码以提供更好的范围,如您所见,我正在使用带有 sheet 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);
}
}
推荐阅读
- linux - 清漆 ESI 缓存 - 远程 url 返回 404
- reactjs - 在反应中将一些值从一页传递到另一页
- postgresql - Postgres lo_import 从其他表文本数据导入大对象
- javascript - JavaScript 编译器错误 - Google 跟踪代码管理器
- javascript - Wordpress 新页面和帖子未向公共用户显示 (IIS 8)
- java - MenuItem(系统托盘)的文本颜色
- php - 如何将 2 个 PHP 数组转换为 1 个 JSON 对象数组?
- excel - EXCEL:带有 sumproduct 或 rank.avg 的列表的平均排名?
- php - 如何在php中打印由特殊字符组成的列的内容
- javascript - 在函数中声明没有 var 的变量