我正在为网络应用程序在谷歌应用程序脚本中创建一个销售点。我正在从谷歌表中提取数据......当我扫描 upc 代码时加载到网络应用程序中。我的目标是在容器的表单端加载信息,然后将该数据传输到单独容器中的收据......现在我无法加载信息......这是我到目前为止所拥有的...... .
我的电子表格看起来像......
upc 名称 描述 价格 税 手头数量 362032140056 薯条酥脆 12.99 0.05 *这将是其他工作表的计算字段
我的代码....
function getItem(scan_item){
var ss = Spreadsheetapp.getactiveSpreadsheet();
var ws = ss.getSheetByName("Items");
var data = ws.getRange(1,1,ws.getLastRow()-1,1).getvalues();
var itemsList = data.map(function(r){ return r[0]; });
var nameList = data.map(function(r){ return r[1]; });
var position = itemsList.indexOf(scan_item);
if(position > 0){
return nameList[position];
} else {
return "Item Not Found!"
}
}
document.getElementById("scan-id").addEventListener("input",getItemInfo);
function getItemInfo(){
var scan_item = document.getElementById("scan-id").value;
if(scan_item.length === 12){
google.script.run.withSuccessHandler(updateItemInfo).getData(scan_item);
}
}
function updateItemInfo(name){
document.getElementById("name-id").value = name;
}
我的 html.... 带有禁用 txt 框x 的纯文本框,用于我想提取的数据...
<section class="item-info form">
<div class="item-container" id="item-info">
<div class="row">
<div class="input-field col s6">
<label for="disabled"class="active">Item:</label>
<input disabled value= "": id="name-id" type="text" class="validate">
<input disabled value="" id="description-id" type="text" class="validate">
</div>
</div>
<div class="row">
<div class="input-field col s1">
<label for="disabled">Price:</label>
<input disabled value="" id="price-id" type="text" class="validate">
</div>
</div>
<div class="row">
<div class="input-field col s12">
<label for="disabled">QTY:</label>
<input disabled value="" id="qty-id" type="text" class="validate">
</div>
</div>
<div class="row">
<div class="input-field col s2">
<label for="disabled">On Hand:</label>
<input disabled value="" id="onHand-id" type="text" class="validate">
</div>
</div>
<div class="row">
<form class="col s12">
<div class="row">
<div class="input-field col s12">
<label for="scan_item">SKU</label>
<input placeholder="Scan Item" id="scan-id" type="text" class="validate">
</div>
</div>
</div>
</section>
到目前为止,如果我输入列表中的 upc,我不会收到“找不到项目!”的提示。信息... 如果我输入一个不在列表中的 upc,消息就会出现......所以我必须有正确的东西......我只需要名字和其他信息来完成......任何人都可以帮助我......我还想添加回车以移动到收据..我知道我必须为详细命令显示更多代码.. .