微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何从 google appscript

如何解决如何从 google appscript

我在我的项目中创建了两个名为“Input.html”和“output.html”的页面,其中单击 input.html 中的提交按钮,输出将打印在 output.html 中

但是我不知道如何从一个页面调用一个页面

代码.gs

function doGet() {
  return HtmlService.createTemplateFromFile('Input')
      .evaluate().setTitle("GL StyleGuide").setFaviconUrl("https://fonts.ab24dp.png");
}

在输入页面中有一个文本区域和一个提交按钮,我希望我的输出在 output.html 页面上打印。 修改:Input.html的示例html如下

<div>
  <label id="label">Please Enter CSS</label>
      <textarea id="input-textarea"></textarea>
      
      <?var url = ScriptApp.getService().getUrl();?><a href='<?=url?>?v=form'><input type='button' id="submit" name='button' onclick="addRow()" value='Get Style Guide'></a>      
</div>

解决方法

所以我在我的一个网络应用程序中使用的一种方法是我有一个 <div id = "app"></div> 在我想要加载另一个 HTML 的页面中。

然后我有这个功能来评估我的视图 代码.gs

function loadPartialHTML_(params) {
  var htmlSrv = HtmlService.createTemplateFromFile(params);
  var html = htmlSrv.evaluate().getContent();
  return html;
}

然后在我的主 Html 中,我有这个函数,它接受 myView Html 并将其填充到定义的 div 中。

function loadView(options){ //loadView Function to Access Server side functions with options being an object of Parameter


var id = typeof options.id === "undefined" ? "app" : options.id; //checking if Id of Element is undefined then "app" will be used else parameter passed

var cb = typeof options.callback === "undefined" ? function(){} : options.callback; //if undefined then a blank function else function called

google.script.run.withFailureHandler(function (e){
    displayToast("errorNotification",e.message);
    loadingEnd();
}).withSuccessHandler(function(html){ //accessing server side function which will be supplied in object with "func:" which will return HTML

document.getElementById(id).innerHTML = html; //this is a call back funtion which gets html from server side and setting defined element to that return

typeof options.params === "undefined" ? cb() : cb(options.params); //if parameters were not supplied thn callback funtion with parameters else with parameters
})[options.func]();
}

myView HTML 将是一个只有元素的 HTML 文件,没有标题、正文等。

您可以使用事件处理程序在事件发生后加载视图。 此外,这不是我的工作,我是从一个很棒的 Youtube 频道学到的,这里有这个策略的链接,以防你卡在某个地方:Locator Strategies

我希望它能帮助您获得所需的结果。 谢谢。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?