我很新的JavaScript,并试图玩弄在谷歌电子表格和电子邮件的邮件合并功能。 我复制教程脚本,并做了一些必要的改变(至少是我能想到的)。 但是,当我试图运行该脚本,我得到了类型错误:无法读取零属性“长度”。 (线43)
上面提到的线43是用于以下循环。 是否有人可以帮助让我知道是固定的东西,所以我可以运行脚本?
// Replaces markers in a template string with values define in a JavaScript data object.
// Arguments:
// - template: string containing markers, for instance ${"Column name"}
// - data: JavaScript object with values to that will replace markers. For instance
// data.columnName will replace marker ${"Column name"}
// Returns a string without markers. If no data is found to replace a marker, it is
// simply removed.
function fillInTemplateFromObject(template, data) {
var email = template;
// Search for all the variables to be replaced, for instance ${"Column name"}
var templateVars = template.match(/\$\{\"[^\"]+\"\}/g);
// Replace variables from the template with the actual values from the data object.
// If no value is available, replace with the empty string.
for (var i = 0; i < templateVars.length; ++i) {
// normalizeHeader ignores ${"} so we can call it directly here.
var variableData = data[normalizeHeader(templateVars[i])];
email = email.replace(templateVars[i], variableData || "");
}
return email;
}