Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用GoogleApps脚本将模板化变量传递给HTML文件中的服务器端处理程序函数?_Javascript_Templates_Google Apps Script_Server_Handler - Fatal编程技术网

Javascript 如何使用GoogleApps脚本将模板化变量传递给HTML文件中的服务器端处理程序函数?

Javascript 如何使用GoogleApps脚本将模板化变量传递给HTML文件中的服务器端处理程序函数?,javascript,templates,google-apps-script,server,handler,Javascript,Templates,Google Apps Script,Server,Handler,我想将一个模板化的对象变量传递给GAS中的服务器端函数。我希望看到按钮呈现,然后在填写付款详细信息并单击“付款”后,我希望看到handleTxn()函数使用content对象作为其参数之一成功执行 但是,由于按钮甚至不渲染,因此什么也不会发生。它默默地失败了 var content = <?!= content ?>; google.script.run.handleTxn(data, details, content); index.html 价格:$ //此功能在网页上显示智

我想将一个模板化的对象变量传递给GAS中的服务器端函数。我希望看到按钮呈现,然后在填写付款详细信息并单击“付款”后,我希望看到
handleTxn()
函数使用
content
对象作为其参数之一成功执行

但是,由于按钮甚至不渲染,因此什么也不会发生。它默默地失败了

var content = <?!= content ?>;
google.script.run.handleTxn(data, details, content);
index.html

价格:$
//此功能在网页上显示智能支付按钮。
贝宝,按钮({
createOrder:函数(数据、操作){
//此功能设置交易的详细信息,包括金额和行项目详细信息。
return actions.order.create({
购买单位:[{
金额:{
价值:
}
}]
});
},
onApprove:功能(数据、操作){
//此函数用于捕获交易中的资金。
返回actions.order.capture().then(函数(详细信息){
var alertText=(
“\n我们向您收费:$”
+
);
警报(警报文本);
var含量=;
google.script.run.handleTxn(数据、细节、内容);
});
}
}).render(“#贝宝按钮容器”);

希望看到handleTxn()函数的结果。在哪里?@TheMaster:我想更清楚一点,我应该说我希望看到使用
内容
对象成功执行
handleTxn()
函数。我现在将编辑问题以反映这一点。否。它默默地失败了。你是怎么得出这个结论的?你期望得到什么切实的结果?希望看到handleTxn()函数成功执行是什么让你认为它没有成功执行?@TheMaster:首先,我希望按钮能够呈现。如果它们没有呈现,我希望脚本执行记录中会出现错误消息。但是按钮没有渲染,也没有错误消息。这是关于修复按钮没有渲染的问题还是关于如何传递模板变量的问题?
[...]
var template = HtmlService.createTemplateFromFile(HTML_FILENAME);
template.content = values;
var htmlOutput = template.evaluate();
[...]

function handleTxn(data, details, content) {
  // do stuff
}
<!DOCTYPE html>
  <!-- source: https://developer.paypal.com/docs/checkout/integrate/ -->
  <html>
    <body>
      <div class="container">
        Price: $<?= content.price ?></td>
        <div id="paypal-button-container"></div>
      </div>
      <script
        src="https://www.paypal.com/sdk/js?client-id=SB_CLIENT_ID">
      </script> 
      <script>
        // This function displays Smart Payment Buttons on your web page.
        paypal.Buttons({
          createOrder: function(data, actions) {
            // This function sets up the details of the transaction, including the amount and line item details.
            return actions.order.create({
              purchase_units: [{
                amount: {
                  value: <?!= content.price ?>
                }
              }]
            });
          },
          onApprove: function(data, actions) {
            // This function captures the funds from the transaction.
            return actions.order.capture().then(function(details) {
              var alertText = (
                '\nWe charged you: $'
                +
                <?!= content.price ?>
              );
              alert( alertText );
              var content = <?!= content ?>;
              google.script.run.handleTxn(data, details, content);
            });
          }
        }).render('#paypal-button-container');
      </script>
    </body>
  </html>