【发布时间】:2021-05-22 02:10:56
【问题描述】:
我试图在 Google Script 上使用映射在 City (id="city") 字段中输入一个值,并使用下面的脚本显示价格 (id="price")。下面的代码不起作用,也没有在价格文本框中提供任何结果。此外,是否可以执行多个条件?我的意思是价格将根据城市、产品和数量显示。我提供了下面的图片。谢谢!
<script>
document.getElementById("btn").addEventListener("click",getPrice);
function getPrice(){
vCity = document.getElementById("city").value;
google.script.run.withSuccessHander(updatePrice).getAmount(vCity);
}
function updatePrice(myprice) {
document.getElementById("price").value = myprice;
}
</script>
这是我的 gs。
function doGet(e) {
return HtmlService.createHtmlOutputFromFile("page");
}
function getAmount(city) {
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1FhWlaXixXPxq8EnHICfVR207aIkxtkzOgvdvt3hHuuI/edit#gid=0");
var ws = ss.getSheetByName("Pricing");
var data = ws.getRange(1, 1, ws.getLastRow(),2).getValues();
var cityList = data.map(function(r){ return r[0]; });
var priceList = data.map(function(r){ return r[1]; });
var position = cityList.indexOf(city);
if(position > -1){
return priceList[position];
} else {
return "Unavailable";
}
【问题讨论】:
标签: javascript google-apps-script google-sheets mapping