我的Index.html有一个标记,当我在Google表格上打开“模态对话框”时,我可以在其中运行以下代码,并使用google.run
进行调用-Index.html-
<script>
function onSuccess(info)
{
...add options to select tags...
}
function fillOtherMenus(info)
{
...add options to other select tags...
}
google.script.run.withSuccessHandler(onSuccess).getDropdownMenus();
google.script.run.withSuccessHandler(fillOtherMenus).getOtherDropdownMenus();
</script>
目前,此代码适用于onSuccess函数;但是我无法弄清楚为什么它对fillOtherMenus函数不起作用。
答案 0 :(得分:0)
这是一个类似于我认为您要完成的示例...正在加载下拉列表。在这种情况下,我会在DOM加载后立即加载。
<script>
$(function(){
$('#sel1').css('background-color','#ffff00');
google.script.run
.withSuccessHandler(function(vA){
updateSelect(vA);
anotherFunction();
})
.getTrackFiles();
});
function updateSelect(vA,id){
$('#sel1').css('background-color','#ffffff');
var id=id || 'sel1';
var select = document.getElementById(id);
select.options.length = 1;
for(var i=0;i<vA.length;i++)
{
select.options[i+1] = new Option(vA[i].name,vA[i].id);
}
}
....
</script>
Google脚本:
function getTrackFiles() {
var GPSTracksFolder=DriveApp.getFolderById(getGlobal('GPSTracksFolderId'));
var tracks=GPSTracksFolder.getFiles();
var files=[];
while(tracks.hasNext()){
var trackfile=tracks.next();
files.push({name:trackfile.getName(),id:trackfile.getId()});
}
return files.sort(compareTrackFileNames);
}
function compareTrackFileNames(fa,fb) {
var a=fa.name;
var b=fb.name;
Logger.log('FileName a: %s',a);
Logger.log('a-0: %s, 1: %s, 2: %s, 3: %s, 4: %s, 5: %s, 6: %s',Number(a.slice(0,4)),Number(a.slice(5,7)-1),Number(a.slice(8,10)),Number(a.slice(11,13)),Number(a.slice(14,16)),Number(a.slice(17,19)),Number(a.slice(20,22))*10);
Logger.log('FileName b: %s',b);
Logger.log('b-0: %s, 1: %s, 2: %s, 3: %s, 4: %s, 5: %s, 6: %s',Number(b.slice(0,4)),Number(b.slice(5,7)-1),Number(b.slice(8,10)),Number(b.slice(11,13)),Number(b.slice(14,16)),Number(b.slice(17,19)),Number(b.slice(20,22))*10);
var vA=new Date(Number(a.slice(0,4)),Number(a.slice(5,7)-1),Number(a.slice(8,10)),Number(a.slice(11,13)),Number(a.slice(14,16)),Number(a.slice(17,19)),Number(a.slice(20,22))*10).valueOf();
var vB=new Date(Number(b.slice(0,4)),Number(b.slice(5,7)-1),Number(b.slice(8,10)),Number(b.slice(11,13)),Number(b.slice(14,16)),Number(b.slice(17,19)),Number(b.slice(20,22))*10).valueOf();
Logger.log('vA: %s vB: %s vA-Vb: %s',vA,vB,vA-vB);
Logger.log('**********************');
return vB-vA;
}