0
我想从一个基于这里发布的问题Previous questioe posted by @Kron011的问题的电子表格中填充一个列表,我正在挣扎。我添加了这些行我.GS文件:Google html从电子表格创建列表
function getMenuListOne(){
return SpreadsheetApp.openbyId('spreadsheet_key').getSheetByName('sheet1')
.getRange(row, column, numRows, numColumns).getValues();
}
,我添加了这行我的HTML文件:
<select id="menu">
<option></option>
<option>Google Chrome</option>
<option>Firefox</option>
</select>
<script
src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
// The code in this function runs when the page is loaded.
$(function() {
google.script.run.withSuccessHandler(showThings)
.getMenuListFromSheet();
google.script.run.withSuccessHandler(showMenu)
.getMenuListFromSheet();
});
function showThings(things) {
var list = $('#things');
list.empty();
for (var i = 0; i < things.length; i++) {
list.append('<li>' + things[i] + '</li>');
}
}
function showMenu(menuItems) {
var list = $('#menu');
list.find('option').remove(); // remove existing contents
for (var i = 0; i < menuItems.length; i++) {
list.append('<option>' + menuItems[i] + '</option>');
}
}
</script>
一如以往我的痛苦有限的经验是阻碍我的努力。我可以得到一个新的菜单框出现并显示我想要的正确结果,但我无法使现有的框显示相同的列表。现有的箱码目前:
<input type="text" name="site" list="depotslist" id="site" class="form-control" placeholder="Select depot/site" required>
<datalist id="depotslist">
<option value="one">
<option value="two">
</datalist>
但有人请点我在正确的方向这我现有的菜单框的部分,我需要改变,以获得两位沟通?
UPDATE 7月23日
添加以下代码来获取另一份清单,以从另一个源操作:
$(function() {
google.script.run.withSuccessHandler(showThings2)
.getMenuListSources();
google.script.run.withSuccessHandler(showMenu2)
.getMenuListSources();
});
function showThings2(things2) {
var list2 = $('#things2');
list.empty();
for (var i = 0; i < things2.length; i++) {
list2.append('<li>' + things2[i] + '</li>');
}
}
function showMenu2(menuItems2) {
var list2 = $('#menu2');
var box2 = $('#sourcelist');
list2.find('option').remove(); // remove existing contents
for (var i = 0; i < menuItems2.length; i++) {
list2.append('<option>' + menuItems2[i] + '</option>');
box2.append('<option>' + menuItems2[i] + '</option>');
}
}
这些线路中的.GS文件:
var Bvals = SpreadsheetApp.openById(ssKey).getSheetByName('SourceCodes').getRange("C3:C").getValues();
var Blast = Avals.filter(String).length;
return SpreadsheetApp.openById(ssKey).getSheetByName('SourceCodes').getRange(3,3,Blast,1).getValues();
谢谢杰拉尔多,这正是我之后的事情。 – witham
赫拉尔多,如果我想从一张纸上创建另一个列表,我需要做些什么才能做出独特的或改变来允许这个?我尝试添加完全相同的代码并更改了行'var box = $('#');'但其他列表未显示我期望的条目。 – witham
这些新列表显示了什么?那些是同样的列表吗?在选择器中使用#时,是指示要选择的元素的ID。所以请确保元素具有唯一的ID。 – Gerardo