0

我一直在尝试构建一个小型应用程序,该应用程序从列表框中获取所选项目并将其附加到将要上传的文件的文件名中。我可以正确显示所有内容,并且文件已上传,但应附加到文件名的值是“未定义”。这是一个示例:

 function doGet(e) {

 var app = UiApp.createApplication().setTitle("Upload CSV to Sheet");

 var panel = app.createVerticalPanel();
 var listBox = app.createListBox().setName('myList').setId('myList').setWidth('80px');
 listBox.addItem('Value1');
 listBox.addItem('Value2');
 listBox.addItem('Value3');
 listBox.addItem('Value4');

 panel.add(listBox);
 app.add(panel);

   var formContent = app.createVerticalPanel();
   formContent.add(app.createFileUpload().setName('thefile'));
   formContent.add(app.createSubmitButton('Submit'));
   var form = app.createFormPanel();
   form.add(formContent);
   app.add(form);
   return app;
 }

function doPost(e) {
var fileBlob = e.parameter.thefile;
var app = UiApp.getActiveApplication();
   var doc = DocsList.createFile(fileBlob).rename(e.parameter.myList+Utilities.formatDate(new Date(), "GMT", "MM-dd-yy"));
   return app;
 }

如何获取文件名以从 listBox 中获取值?

4

1 回答 1

2

您将其添加listBox到应用程序中,而不是将其添加到表单面板内容中。这有两个后果:

1 - 提交后列表保持可见

2 - 列表没有收到,doPost因为它不在表格中......

试试这样:

function doGet() {

 var app = UiApp.createApplication().setTitle("Upload CSV to Sheet");

 var panel = app.createVerticalPanel();
 var listBox = app.createListBox().setName('myList').setId('myList').setWidth('80px');
 listBox.addItem('Value1');
 listBox.addItem('Value2');
 listBox.addItem('Value3');
 listBox.addItem('Value4');

 panel.add(listBox);

   var formContent = app.createVerticalPanel();
   formContent.add(app.createFileUpload().setName('thefile'));
   formContent.add(app.createSubmitButton('Submit'));
   formContent.add(panel);
   var form = app.createFormPanel();
   form.add(formContent);
   app.add(form);
   return app;
 }

function doPost(e) {
  var fileBlob = e.parameter.thefile;
  var doc = DocsList.createFile(fileBlob).rename(e.parameter.myList+' '+Utilities.formatDate(new Date(), "GMT", "MM-dd-yy"));
  var app = UiApp.getActiveApplication();
  return app;
 }
于 2013-03-22T17:58:18.783 回答