我一直在尝试构建一个小应用程序,它从列表框中获取所选项目并将其附加到将要上载的文件的文件名。我可以正确显示所有内容,并且文件上传,但应该附加到文件名的值是'undefined'。这是一个示例:
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获取值?
答案 0 :(得分:2)
您已将listBox
添加到应用中,而不是将其添加到formpanel内容中。
这有两个后果:
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;
}