use*_*629 8 html web-applications google-sheets google-apps-script
我正在尝试将对象(工作表行的内容)传递给应用程序脚本模板。您可以在屏幕截图中看到该行。
我在应用程序脚本中的函数包含:
var sendableRows = rows.filter(function (row) { //ONLY CHECKED ROWS.
return row['Index'] == true;
});
var sendableRow = sendableRows[0];
Logger.log('sendableRow '+ JSON.stringify( sendableRow));
var html = HtmlService.createTemplateFromFile('RowPopup');
html.row = JSON.stringify(sendableRow);
var h =html.evaluate();
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.showModalDialog(h, 'Create Documents');
Run Code Online (Sandbox Code Playgroud)
记录器语句产生:
sendableRow {"Index":true,"Timestamp":"2019-02-12T21:09:14.000Z","FROM":222222,"CONVERSATION":"THIS IS A TEST","ME":"","relativeRow":14,"absoluteRow":15}
Run Code Online (Sandbox Code Playgroud)
我的 Rowpopup.html 是:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script>
// Prevent forms from submitting.
function preventFormSubmit() {
var forms = document.querySelectorAll('forms');
for (var i = 0; i < forms.length; i++) {
forms[i].addEventListener('submit', function(event) {
event.preventDefault();
});
}
}
window.addEventListener('load', preventFormSubmit);
function handleFormSubmit(formObject) {
// the output from form goes to processDocBuildHtml
google.script.run
.withSuccessHandler(updateUrl)
.processRowPopupHTML(formObject);
}
function updateUrl(url) {
var div = document.getElementById('output');
div.innerHTML = '<a href="' + url + '">Sent!</a>';
}
</script>
</head>
<body>
<form id="myForm" onsubmit="handleFormSubmit(this)">
<div>
<label for="optionList">Click me</label>
<select id="optionList" name="email">
<option>Loading...</option>
</select>
</div>
<br>
<div>
</div>
<br>
<div>
<textarea name="message" rows="10" cols="30">
The cat was playing in the garden.
</textarea>
</div>
<div id="textboxes"></div>
<div id="insert"></div>
<input type="submit" value="Submit" />
</form>
<div id="output">
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="//rawgithub.com/indrimuska/jquery-editable-select/master/dist/jquery-editable-select.min.js"></script>
<link href="//rawgithub.com/indrimuska/jquery-editable-select/master/dist/jquery-editable-select.min.css" rel="stylesheet">
<script>
function getConversations() {
var jsonRow = <?= row ?>; //PASSED IN JSON
console.log('row');
var myObj = JSON.parse(jsonRow);
console.log(myObj['CONVERSATION']);
return myObj['CONVERSATION'];
}
</script>
</body>
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我看到:
这显示了“监狱长”的一些问题。
此外,我没有看到输出到控制台的预期数据:
console.log('row');
var myObj = JSON.parse(jsonRow);
console.log(myObj['CONVERSATION']);
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
Rub*_*bén 10
您的客户端代码从不调用getConversations
,这就是您在控制台上看不到它的原因。在执行此操作的许多方法中,您可以通过在<script>
标签之间添加以下内容来添加 IIFE 来调用该函数
(function (){getConversations()}());
Run Code Online (Sandbox Code Playgroud)
(function (){getConversations()}());
Run Code Online (Sandbox Code Playgroud)
function myFunction(){
var html = HtmlService.createHtmlOutputFromFile('index');
SpreadsheetApp.getUi().showModalDialog(html, 'Test')
}
Run Code Online (Sandbox Code Playgroud)
所以不是你,是谷歌
我知道这个答案与这个OP无关,而且我应该发布的地方不合适,但是对于将来到达此页面的其他人,我在这里留下一个答案,因为我很难解决类似的问题。
\n我认为这个错误意味着我们无法从 HTML 文件连接到脚本编辑器中编写的脚本。
\n所以基本上你可以忽略这个错误消息(也许。如果没有,请告诉我正确的功能。)
\n对我来说,执行时发生了错误google.script.run.myFunction()
。所以,一开始,我认为错误阻止了这次执行。然而,该错误与本次执行完全无关。这是另一个问题,我通过使用发现了我的问题发生的原因withFailureHandler(onFailure)
。它发出一条错误消息。(更多信息请参见/sf/answers/2310575291/)
正如 Rub\xc3\xa9n 先生所说“所以这不是你的问题,而是 Google 的问题”,这个错误可以很容易地重播。请不要对此消息感到困惑。我认为错误消息(“在传输或处理此请求期间出现错误。错误代码 = 10,路径 = /wardeninit”)是无用的。\nRuben\ 的精彩帖子是这样的 -> https: // stackoverflow.com/a/54756933/3077059
\n