【问题标题】:Google Apps Script HtmlService nested createHtmlOutputFromFile to create JQueryGoogle Apps 脚本 HtmlService 嵌套 createHtmlOutputFromFile 以创建 JQuery
【发布时间】:2015-05-19 14:51:42
【问题描述】:

我对此很陌生。

我使用 Google Apps 脚本创建了一个 JQuery WebApp,这对我来说是全新的和令人兴奋的。 在过去的几天里,我阅读和学习了很多东西,试着把事情放在一起。

我的出发点是一些示例,并从这里和那里获取了一些部分,最后让它运行起来。

但是有很多问题,我最大的一个问题是构建 HTML 的东西。

应用程序使用不同的 JQuery 页面和导航栏来更改/访问它们。 我的第一个想法是只对导航栏进行一次编码,并将其动态包含在所需的位置。但我无法让它工作。

这是我得到的:

代码.gs

  var template = HtmlService.createTemplateFromFile('Index');
  return template.evaluate()
      .setTitle('myAPP')
  .setSandboxMode(HtmlService.SandboxMode.IFRAME);

索引.html

  <!-- Include meta tag to ensure proper rendering and touch zooming -->
  <meta name="viewport" content="initial-scale=1, maximum-scale=1">
  <!-- Include jQuery Mobile stylesheets -->
  <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.css">

  <!-- Include the jQuery library -->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <!-- Include the jQuery Mobile library -->
  <script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script>

<!-- Store data passed to template here, so it is available to the
     imported JavaScript. -->
<script>
  var access_token = <?= access_token ?>;
</script>



<!-- Use a templated HTML printing scriptlet to import JavaScript. -->
<?!= HtmlService.createHtmlOutputFromFile('Script').getContent(); ?>

Script.html

这里是我使用的所有 JQuery 代码。 在他想要包含导航栏的时候,我尝试与上述相同:

<?!= HtmlService.createHtmlOutputFromFile('Navbar').getContent(); ?>

但它不起作用。我还尝试将其包含到&lt;script&gt; ... &lt;/script&gt;

我真的不明白为什么它第一次起作用,但第二次嵌套时不起作用。

===== 编辑 - 这是我的演示 ====

https://script.google.com/d/1jwKy9OJp5jD95NkaAwLFTs0LPSxlP9eW2iWdNXuizfFxaKGw-iWZBV3z/edit?usp=sharing

您可以在 JQuery.html 的第 5 行看到我想要“包含”导航栏的位置。

===== 干杯,

海子

【问题讨论】:

    标签: jquery html google-apps-script


    【解决方案1】:

    我使用它来工作:

    索引.html

    <!-- Include meta tag to ensure proper rendering and touch zooming -->
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <!-- Include jQuery Mobile stylesheets -->
    <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.css">
    
    <!-- Include the jQuery library -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <!-- Include the jQuery Mobile library -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquerymobile/1.4.5/jquery.mobile.min.js"></script>
    
    <!-- Store data passed to template here, so it is available to the
     imported JavaScript. -->
    
    <?!= include('JQuery'); ?>
    <?!= include('Navbar'); ?>
    

    code.gs

    function include(filename) {
      return HtmlService.createHtmlOutputFromFile(filename).getContent();
    };
    

    【讨论】:

    • 感谢您的回答。但我无法让它醒来。我设置了一个完整的演示,显示了整个代码。请看一下我编辑的初始帖子。
    • 对不起,不,这不起作用。您的答案与我的问题不匹配,因为我需要包含在 JQuery.html 中,而不仅仅是在 Index.html 中。请看我的Demo。我想在 JQuery.html 内的不同位置使用导航栏。仅仅是因为我希望所有 JQuery 页面中的所有导航栏都只有一个来源。第 5 行中的第一个实现。没有工作。 :-(
    • index.html 中包含的任何 CSS 或脚本均可用于整个应用程序。
    • 感谢您提供的信息!但这并没有改变我不能按照我的意愿在 JQuery.html 中使用我的导航栏的事实。 :-( 我可能很愚蠢,而且肯定是这方面的初学者,但你能帮我处理语法和写作吗?
    • 不,我不会承诺为你做任何事情。在网站上收到或提供的任何帮助都是完全自愿的。我可能永远不会再看这篇文章了,我可能会突然想做得更多,并继续努力。你只需要管理你的期望。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-18
    • 1970-01-01
    • 2013-09-06
    • 2015-02-22
    • 2014-11-26
    相关资源
    最近更新 更多