【发布时间】:2015-02-26 03:32:20
【问题描述】:
我正在为文档创建一个 Google 插件。所以我使用 html、scriptlet 和 java。一切都运行良好,但突然间,我收到此错误,我不知道如何解决。
当我运行 html 时,出现错误,如表所示。在开发人员工具中,显示以下错误: 1. Google Apps 脚本:回调函数不支持此操作。 2. 给定范围不属于当前选择的文档。 3. G.Y0
我如何利用这些信息找到错误的位置?
每个请求的附加信息............
抱歉,我正在使用 javascript。
我的 html 文件只有两个服务器端函数调用。第一种是通过 scriptlet,它在加载 html 之前加载。此调用函数返回一个数组,用于为表格创建带有动态 html 的侧边栏。
<? var rubric = getRubric(); ?>
第二个是一个按钮,位于侧边栏中。该按钮存储位于侧边栏中的单选按钮 ID,然后将它们发送到服务器端函数。我在上面放了一个 withFailureHandler。
<td class="tableCalcButton"><input type="button" class="button" value="Fill Rubric" onclick= "fillRubricA()" /></td>
<script>
function fillRubricA(){
var selection = [];
var matrix = document.getElementsByName('rbRubric').length; // this = 20 a 4x5 matrix.
selection[0] = [ [document.getElementById('rbRubric11').value], [ matrix / (document.getElementById('rbRubric11').value - 1) + 1 ] ];
for ( var r = 1; r < selection[0][0]; r++) {
for ( var c = 1; c < selection[0][1] ; c++) {
if (document.getElementById( 'rbRubric' + r + c).checked == true) { selection[r] = [c];}
}
}
google.script.run.withFailureHandler(onFailure)
.fillRubric(selection);
console.log('[0][0] ' +selection[0][0]);
}
function onFailure(error){ alert(error.message + ' Server is not found. Try your selection again.'); }
</script>
服务器端函数如下所示...
function getRubric() {
// there is code here that I know works fine. Then I make a function call.
// Locate Rubric Table
var rubricTable = findRubricTable();
if (rubricTable == null ){
var alert = ui.alert('Server not found. Try your selection again.');
return;
}
// there is more code that works.
// loadRubric is the array I send back to scriptlet that called it.
return loadRubric;
}
从 getRubric() 中调用此服务器函数。
function findGradeTable(){
//the code here does not call another function and works fine.
//It finds the correct table id number and returns it.
return rubricTable;
}
最后,单选按钮调用该函数,该函数不调用其他函数并对文档进行最终格式更改。
function fillRubric(selection){
//This javascript works fine.
}
【问题讨论】:
-
您使用的是 Java 还是 Javascript?他们甚至不接近同一件事。你的文字说“Java”,你的标签说“Javascript”。此外,您可能必须向人们展示相关代码才能提供帮助。
-
jfriend00,我正在使用 JavaScript。我已经按照您的建议添加了更多详细信息。总的来说,我知道代码运行良好。但是,我仍在努力理解和实现成功的回调。如果您能看到问题所在,我将不胜感激。或者,如果你能指导我如何使用谷歌开发工具来确定回调错误发生的位置,那就太好了。
标签: javascript google-apps-script callback client-server add-on