【发布时间】:2021-07-02 22:48:34
【问题描述】:
您好,我正在尝试使用 HTML 和 Google 脚本获取下拉列表。选项应取自 Google 电子表格。不幸的是,我的清单一直是空的。选项不会出现。有人可以帮忙吗?
代码 GS
function getListCars(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var carsheet = ss.getSheetByName("Rejestraut");
var lastrow = carsheet.getLastRow();
return carsheet.getRange(2,2,lastrow-1,1);
}
HTML
...<script>
function loadCars(){
google.script.run.withSuccessHandler(function(ar)
{
var carsSelect = document.getElementById("numeryrejestracyjne");
console.log(ar);
let option = document.createElement("option");
option.value="";
option.text = "";
carsSelect.appendChild(option);
ar.forEach(function(item, index)
{
let option = document.createElement("option");
option.value = item[1];
option.text = item[1];
carsSelect.appendChild("option");
});
}).getListCars();
};
</script>
<select id="numeryrejestracyjne">
</select>
<script>loadCars();</script>
【问题讨论】:
标签: javascript html google-apps-script google-sheets