0

我正在尝试使用 javascript 从谷歌驱动器访问文件。我已经成功地做到了这一点。现在我想在弹出窗口中显示文件。请参阅下面的代码,一定有我不知道的东西。

//this code successfully retrieve files, I am trying to put the results into an array to access them later. 
function listFiles(search, owner) {
    var file_results = new Array();
    gapi.client.drive.files.list({
        'pageSize': 10,
        'fields': "nextPageToken, files(id, name, webViewLink)",
        'q': "fullText contains '" + search + "' and trashed=false and '" + owner + "' in owners"
    }).then(function(response) {
        var files = response.result.files;
        if (files && files.length > 0) {
            for (var i = 0; i < files.length; i++) {
                var file = files[i];
                file_results.push(file);
            }
        } else {
            return false;
        }
    });
    return file_results;
}
//here I am trying to run the function and get the list of files
$("#search_files").click(function(e) {
    e.preventDefault();
    var owner = $(this).data('owner');
    var name = $(this).data('name');
    var files = parent.listFiles(name, owner);
    console.log(files);
    //this will log [ 0: {id: xxxxxx name: xxxxxxx webViewLink: xxxxxx }]
    //I would like to check first if there were any results of files 
    //i.e files.length will return 0 even if there were files found. 
    //I tried to access files.id is undefined. files[0] also undefined. 
});
4

0 回答 0