【问题标题】:HTML (sidebar) calling library scripts, possible?HTML(侧边栏)调用库脚本,可能吗?
【发布时间】:2014-12-16 13:13:29
【问题描述】:

我在电子表格的 HTML 中创建了一个侧边栏,一切运行良好,但是当移动到维护所有代码的库时,它停止工作,侧边栏使用的函数现在未定义,我该如何调用直接从侧边栏中的“FuncoesOrcamentoV2”库中的函数?将代码复制到每个电子表格是不切实际的,有几十个。

例子:

form.html

<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/themes/smoothness/jquery-ui.css" /> 
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>

<label for="autocomplete">Select a programming language: </label>
<input id="autocomplete" disabled="true" value="Carregando..." clss="ui-autocomplete ui-front ui-menu ui-widget ui-widget-content">
<input type="button" value="Close" onclick="escrever()" />
<script>
function autoCompletar( comps ){
$( "#autocomplete" ).removeAttr("disabled").removeAttr("value");
    $( "#autocomplete" ).autocomplete({
    source: comps
    });
}
google.script.run.withSuccessHandler( autoCompletar ).arrayObjetos(); //arrayObjetos cannot be called
</script>

code.gs -> FuncoesOrcamentoV2 库中

function doGet(e) {
  return HtmlService.createHtmlOutputFromFile('form.html');
}

function arrayObjetos(){
var composicoes = FuncoesOrcamentoV2.composicoesObject( ),
     arrayFinal = [];

  for( comp in composicoes )
    arrayFinal.push( comp );

  return arrayFinal;
}

【问题讨论】:

标签: html google-apps-script google-sheets sidebar


【解决方案1】:

不是最优雅的方式,但使用 eval() 的形式适用于我的情况:

code.gs 在每张纸上:

function funcoesOrcamento( funcao, args ){
  if(args)
    args = args.split("\!|");
  else
    args = [];

  return FuncoesOrcamentoV2[ funcao ].apply(this, args);
}

在 HTML 侧边栏上:

google.script.run.withSuccessHandler( salvaNivelColuna ).funcoesOrcamento( "nivelColuna" );
google.script.run.withSuccessHandler( autoCompletar ).funcoesOrcamento( "arrayObjetos" );

【讨论】:

    猜你喜欢
    • 2022-01-25
    • 2012-10-14
    • 1970-01-01
    • 1970-01-01
    • 2021-08-25
    • 1970-01-01
    • 2023-01-29
    • 2013-06-19
    • 2018-09-02
    相关资源
    最近更新 更多