如何刷新标签而不重新加载谷歌应用程序脚本中的页面

时间:2018-02-09 14:29:11

标签: javascript jquery html google-apps-script

我完成了更新单元格,现在我想在点击桌面上使用google-app-script循环的按钮后自动刷新标签。无法理解documentation中的编码。请帮我解决这个问题。谢谢!

HTML

<div  id="tables">
      <? var data = getData();?>
      <table id="tableShift1">
      <caption style="">Shift1</caption>
          <th>   ID   </th>
          <th>   Ldap   </th>
          <th>   Action   </th>
        <? for (var dataList = 1; dataList < data.length; dataList++) {
             if (data[dataList][2] == '') {?>
          <tr >
            <td><?= data[dataList][0] ?></td>
            <td><?= data[dataList][1] ?></td>
            <td><button onclick='google.script.run.setApproved("<?=data[dataList][0]?> ","<?=data[dataList][1]?>")' id='btnApprove'>Approve</button></td>
          </tr>
        <? }  
          } ?>
        </table>


        <table id="tableShift2">
      <caption>Shift2</caption>
          <th>   ID   </th>
          <th>   Ldap   </th>
          <th>   Action   </th>
        </table>
    </div>

<script
src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
// The code in this function runs when the page is loaded.
$(function() {
  google.script.run.withSuccessHandler(showData)
      .getData();
});

function showData(things2) {
  var table = $('#tableShift2');
  var kwit = ',';
  for (var i = 1; i < things2.length; i++) {
    table.append('<tr ><td>' + things2[i][0] + 
    '</td><td style=>' + things2[i][1]+ things2[i][0] + 
    '</td><td ><button onclick="google.script.run.setApproved("'+ things2[i][0] +'","'+ things2[i][1] +'")" id="btnApprove">Approve</button></td></tr>');
  }
}
</script>
  </body>

1 个答案:

答案 0 :(得分:1)

您可以尝试这样的事情:

添加新功能,可以将新数据返回到refreshData()

function showData(things2) {
  var table = $('#tableShift2');
  var kwit = ',';
  for (var i = 1; i < things2.length; i++) {
    table.append('<tr ><td>' + things2[i][0] + 
                 '</td><td style=>' + things2[i][1]+ things2[i][0] + 
                 '</td><td ><button onclick="ApproveAndRefresh("'+ things2[i][0] +'","'+ things2[i][1] +'");" id="btnApprove">Approve</button></td></tr>');
  }
}


function ApproveAndRefresh(data1,data2){//you may need to include i
  google.script.run
  .withSuccessHandler(refreshData)
  .setApproved1(data1,data2);//a modified setApproved on the server that returns the appropriate html to the tableShift2 element
}

function refreshData(hl){
  document.getElementById('tableShift2').innerHTML=hl;
}