要从 Google 电子表格中捕获的 HTML 选择选项 [英] HTML select option to be captured from Google Spreadsheet

查看:16
本文介绍了要从 Google 电子表格中捕获的 HTML 选择选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了几天的时间来克服这个问题,但没有运气.

我在 Google 脚本中有一个 html 页面,我想要一个下拉列表 - 这是按如下方式实现的

<选择名称=来源"><option value="volvo">沃尔沃</option><option value="saab">Saab</option><option value="欧宝">欧宝</option><option value="audi">奥迪</option></选择>

现在,我希望从电子表格中捕获选项字段,而不是手动输入,如果列范围增加或减少,下拉列表应相应更新.

请提供任何解决方法...

问候,

解决方案

要显示数组中的元素而不是数组对象本身,您需要将 DATA 数组包含在 Scriptlet 标签中.而且我认为不需要使用二维数组.正确的语法应该是:

<代码><div><选择><?for (var i = 0; i <option><?!=data[i] ?></option><??></选择>

混合数据获取代码 & 真的是个坏主意模板中的 html UI 代码.您应该使用单独的 gshtml 文件 &按照 Mogsdad 的建议应用优化.

I have been spending days to get over this but no luck.

I have a html page in Google script whereby I want a dropdown list - this is achieved as follows

<div>
<select name="source">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel">Opel</option>
  <option value="audi">Audi</option>
</select>
</div>

Now instead of the manual inputs I want the option fields to be captured from a spreadsheet, if the coloumn range increase or decrease the dropdown list should update accordingly.

Any workarounds please...

Regards,

解决方案

To display the elements in the array instead of the array object itself, you need to include the DATA array inside Scriptlet tags.And I see no requirement to use a 2-dimensional array. The correct syntax should be:

<?
 var sheet   =  SpreadsheetApp.openById(0Avt7ejriwlxudGZfV2xJUGJZLXktQ2RhQU1ugtgtaXc").getSheetByName("MRF Tab");
  var lastRow = sheet.getLastRow();  
  var myRange = sheet.getRange("C3:C"+lastRow); 
  var data    = myRange.getValues();
  ?>
<div>
  <select>
    <? for (var i = 0; i < data.length; ++i) { ?>
      <option><?!= data[i] ?></option>
    <? } ?>
  </select>
</div>

And its really a bad idea to mix data-fetching code & html UI code within a template. You should use separate gs and html files & apply the optimizations as Mogsdad has suggested.

这篇关于要从 Google 电子表格中捕获的 HTML 选择选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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