GAS - 将变量传递给HTML输出,然后传递给Scriptlet [英] GAS - Passing variable to HTML output and then into a Scriptlet

查看:183
本文介绍了GAS - 将变量传递给HTML输出,然后传递给Scriptlet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Code.gs

 函数doPost(e){
...
template.data + = getCustomerData +< br>;
}
返回template.evaluate()。setSandboxMode(HtmlService.SandboxMode.IFRAME);

index.html

  ... 
<?= data?>>

显示的代码显示正确的值。但是,它不会将< br> 转换为html。我不确定为什么它不起作用,因为 template.evaluate()应该返回一个HtmlOutput对象。

解决方案

默认情况下,字符串已经过清理,将特殊字符转换为其HTML编码的等价物(如<正在& lt;)。



在输出HTML时,您必须使用<?!=来避免消毒数据。
$ b

<?!= data? >



查看有关标准&强制打印scriptlets:
https://developers.google .com / apps-script / guides / html / templates#standard_scriptlets

Code.gs

function doPost(e) {
    ...
    template.data += getCustomerData + "<br>";
}
return template.evaluate().setSandboxMode(HtmlService.SandboxMode.IFRAME);

index.html

...
<?= data ?>

The code shown does display the correct values. However, it doesn't translate <br> into html. I'm not sure why it isn't working since template.evaluate() is supposed to return an HtmlOutput object.

解决方案

By default the strings are sanitized, converting special characters to their HTML encoded equivalents (such as < becoming &lt;).

When outputting HTML you must use <?!= to avoid sanitizing the data.

<?!= data ?>

See the details on standard & force-printing scriptlets here: https://developers.google.com/apps-script/guides/html/templates#standard_scriptlets

这篇关于GAS - 将变量传递给HTML输出,然后传递给Scriptlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆