【发布时间】:2021-02-08 10:38:03
【问题描述】:
我有下面的代码,它读取 2 张表格中的数据,country 和 vendor 并为每个表格构建下拉列表。
我想尝试使用类似的方法将它们合并到一个函数中:
var lists = ["country", "vendor"];
lists.forEach()
// or
// for list in lists {}
但坚持使用 .withSuccessHandler()我如何才能将 2 个输入传递给它,例如 list 和 list values?
<script>
function createCountryDropdown() {
//SUBMIT YOUR DATA RANGE FOR DROPDOWN AS THE PARAMETER
google.script.run
.withFailureHandler(onFailure)
.withSuccessHandler(countryDropDown)
.getDropdownList("country");
google.script.run
.withFailureHandler(onFailure)
.withSuccessHandler(vendorDropDown)
.getDropdownList("vendor");
}
function onFailure(err) {
alert('There was an error!' + err.message);
}
//POPULATE COUNTRY DROPDOWNS
function countryDropDown(values) { //Ref: https://stackoverflow.com/a/53771955/2391195
var list = document.getElementById('country');
for (var i = 0; i < values.length; i++) {
var option = document.createElement("option");
// console.log(value[i])
option.value = values[i];
option.text = values[i];
list.appendChild(option);
}
}
//POPULATE Vendor DROPDOWNS
function vendorDropDown(values) { //Ref: https://stackoverflow.com/a/53771955/2391195
var list = document.getElementById('vendor');
for (var i = 0; i < values.length; i++) {
var option = document.createElement("option");
// console.log(value[i])
option.value = values[i];
option.text = values[i];
list.appendChild(option);
}
}
</script>
有什么帮助吗?
【问题讨论】:
-
也许你想要
withUserObject(object)方法?
标签: javascript google-apps-script