我正在尝试定义我的文件保存到的位置。我从最终用户开始向内移动,这意味着UI的开始。我有标签和列表框,但我在列表框中填充了我的Google云端硬盘中的文件夹和子文件夹。最终产品将是:点击下拉菜单 - >选择文件夹将文件保存到 - >点击“提交”,然后将其保存到文件夹中。
这是我到目前为止所做的:(不要介意我的所有笔记。我没有JS经验,也没有编程经验,所以我从原始模板制作者的代码中学习。这就是全部如果需要,可以使用代码:http://pastebin.com/rbvu5Pie)
//look here for code about the listbox to show folders
grid.setWidget(2, 0, app.createLabel('Folder:')); //makes the label "folder" next to the listbox
var list = app.createListBox(); //defines what to do when i say list
grid.setWidget(2, 1, list); //puts the listbox to the right of the label
var folder = DocsList.getAllFolders()[0]; //defines that when i say "folder" it is supposed to get all folders
for (var i = 0; i < folder.length; i++) {
list.addItem(folder[i].getName(),folder[i].getId())
}
//this is the end of the code for the listbox showing folders
感谢大家的帮助,我真的很感激!
答案 0 :(得分:0)
这是一个似乎有用的测试代码。我没有彻底测试它,但它似乎做了它必须做的事情......
我将带有ID的textBox保留为可见,以便更容易调试,但您应该在最终代码中将其设置为不可见。
可能会有一些改进,但它提供了一般的想法......
function doGet(){
var app = UiApp.createApplication();
var curFN = app.createTextBox().setText('MyDrive/').setName('curFN').setId('curFN').setWidth('400');
var curFID = app.createTextBox().setText('x').setName('curFID').setId('curFID').setWidth('400');
var list = app.createListBox().setName('list').setId('list').addItem('please select a folder','x');
var grid = app.createGrid(3,2).setText(0,0,'Choose a folder in your drive').setWidget(0,1,curFN).setWidget(2,1,curFID).setWidget(1,1,list);
var folders = DocsList.getRootFolder().getFolders();
for (var i = 0; i < folders.length; i++) {
list.addItem(folders[i].getName(),folders[i].getId())
}
var handler = app.createServerHandler('folderSelect').addCallbackElement(grid);
list.addChangeHandler(handler);
app.add(grid);
return app;
}
function folderSelect(e){
var app = UiApp.getActiveApplication();
var currentFN = e.parameter.curFN;
var currentFID = e.parameter.list;
Logger.log(currentFID);
var list = app.getElementById('list');
var curFN = app.getElementById('curFN');
var curFID = app.getElementById('curFID');
if(currentFID=='x'){currentFID=DocsList.getRootFolder().getId() ; curFN.setText('MyDrive/')};
var startFolder = DocsList.getFolderById(currentFID);
var folders = startFolder.getFolders();
list.clear().addItem('no other subFolder','x').addItem('Go back to Root','x');
if(folders.length>0){list.clear(); list.addItem('please select a subFolder','x')};
for (var i = 0; i < folders.length; i++) {
list.addItem(folders[i].getName(),folders[i].getId())
}
curFN.setText(currentFN+DocsList.getFolderById(currentFID).getName()+'/');
if(currentFID==DocsList.getRootFolder().getId()){curFN.setText('MyDrive/')};
curFID.setText(currentFID);
return app;
}
应用online here,需要Docslist服务授权