0

I have a docs List dialogue, here is my code so far. How do I get the actual selection from the DocListDialogue though? I keep tried eventInfo.parameter,but that only returned a generic object and I need a file to be returned. Here is my code:

function init() {
   var app = UiApp.createApplication().setTitle("WriteWell");
   var selectionHandler = app.createServerHandler("selectHandler");
   app.createDocsListDialog().showDocsPicker().setDialogTitle("Select File to Open").addSelectionHandler(selectionHandler);
   app.add(app.createVerticalPanel().setId("Panel"));
   return app;
 }

 function doGet(e) {
   return init();
 }

function selectHandler(eventInfo){
  var parameter = eventInfo.parameter;//Selection???
  var app = UiApp.getActiveApplication();
  var panel = app.getElementById("Panel");
  panel.add(app.createLabel(parameter.getId()));//Returns an error
}
4

2 回答 2

1

When inspecting the content of eventInfo.parameter, we see that returns something like this:

{
    source=u01234567890,
    items=[
      {
        id=0Abcd-efgH_ijKLLLmnOPQr0stuvwX,
        name=file_name,
        url=https://docs.google.com/file/d/0Abcd-efgH_ijKLLLmnOPQr0stuvwX/edit?usp=drive_web
      }
    ],
    u01234567890=[
      {
        id=0Abcd-efgH_ijKLLLmnOPQr0stuvwX,
        name=file_name,
        url=https://docs.google.com/file/d/0Abcd-efgH_ijKLLLmnOPQr0stuvwX/edit?usp=drive_web
      }
    ],
    eventType=selection
}

If you need the ID of the selected file, you'll need something like:

...
eventInfo.parameter.items[0].id;
...
于 2013-10-13T19:41:14.717 回答
0

If you want to see what is in the eventInfo you can use

Logger.log(Utilities.jsonStringify(eventInfo));

which in this case would return something like that :

[13-10-13 21:25:21:722 CEST] {"parameter":{"source":"u16052058908","items":[{"id":"0AnZ5_ShBzI6pdHd4SWo0bUJYOEp4VFE4cDI1SUFvZFE","name":"Tracker locaux","url":"https://docs.google.com/a/insas.be/spreadsheet/ccc?key\u003d0AnZ5_ShBzI6pdHd4SWo0bUJYOEp4VFE4cDI1SUFvZFE\u0026usp\u003ddrive_web"}],"eventType":"selection","u16052058908":[{"id":"0AnZ5_ShBzI6pdHd4SWo0bUJYOEp4VFE4cDI1SUFvZFE","name":"Tracker locaux","url":"https://docs.google.com/a/insas.be/spreadsheet/ccc?key\u003d0AnZ5_ShBzI6pdHd4SWo0bUJYOEp4VFE4cDI1SUFvZFE\u0026usp\u003ddrive_web"}]}}

Looking at it you'll see that you can get the object properties you want using (for example) :

var docsInfo = eventInfo.parameter.items;

that will return an array of objects (one for each selected file) that contains file names, IDs and urls

Just iterate this objects array to get what you want from each item.

于 2013-10-13T19:36:09.257 回答