1

我正在尝试定义我的文件要保存到的位置。我从最终用户开始向内移动,这意味着 UI 的开始。我有标签和列表框,但在使用 Google Drive 中的文件夹和子文件夹填充列表框时遇到问题。最终产品将是:单击下拉菜单->选择要保存文件的文件夹->单击“提交”并将其保存到文件夹中。

这是我到目前为止所拥有的:(不要介意我所有的笔记。我的 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

感谢大家的帮助,我真的很感激!

4

1 回答 1

0

这是一个似乎有效的测试代码。我没有彻底测试它,但它似乎做了它必须做的事情......

我让带有 ID 的文本框可见,以便于调试,但您应该在最终代码中将其设置为不可见。

可能需要添加一些改进,但它给出了总体思路......

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;
}

此处在线应用,需要Docslist服务授权

于 2013-08-09T07:53:49.263 回答