3

我从这个 stackoverflow 问答开始,一个很好的开始,谢谢。尝试使用 node.js 遍历保管箱文件夹树, 但我没有使用 node.js。我正在使用直接的Javascript。我不确定答案中提到的计数器增量和减量 - 不确定它们会去哪里。

我正在使用 jQuery.getJSON 来获取元数据。基本上我在这一点上迷路了。我可以从 Dropbox 获取元数据,但在处理函数 pathsToArray 时遇到问题。

函数 dbxGetContents 只是我设置的一个函数,用于执行另一个对 Dropbox 的调用以获取刚刚找到的文件夹的文件夹内容。

function dbxCreateTree(clickFolderName, crumbType, crumbData){

    // Get the OAUTH connection to Dropbox.  It's a call to the JS function dbxConnect()
    var dbxConn = dbxConnect();

    var dbxUrlTree = "https://api.dropbox.com/1/metadata/dropbox/" + clickFolderName;       
    dbxUrlTree = dbxUrlTree + "?";
    dbxUrlTree = dbxUrlTree + dbxConn;

    jQuery.getJSON(dbxUrlTree,
        function(data){

            function pathsToArray(metadataarr,callback){   //Call this function and pass the Dropbox metadata array to it, along with a callback function
                    for (aItem in metadataarr ){  //For every folder or file in the metadata(which represents a specific URL)
                            if (metadataarr[aItem].is_dir){     //It is a folder
                                dropbox.paths.push(metadataarr[aItem].path+"/");   //Write the path of the folder to my array called 'dropbox.paths'
                                dbxGetContents(metadataarr[aItem].path.slice(1),function(err, data){   //We go into the folder-->Call the dropbox API to get metadata for the path of the folder.
                                    if (err){  
                                    }
                                    else {      
                                        pathsToArray(data.contents,function(err){  //Call the function from within itself for the url of the folder.  'data.contents' is where the metadata returned by Dropbox lists files/folders
                                        }); 
                                    }
                                });
                            }
                            else {      //It is a file
                                //dropbox.paths.push(metadataarr[aItem].path);   //Write the path of the file to my array called 'dropbox.paths'
                            }
                        }
            return callback(); //This returns multiple times, instead of only once when everything is ready, and that is the problem!
            };

        pathsToArray(data);

        });     
}

这是 dbxGetContents 函数。

function dbxGetContents(dbxFolderName){

        // Get the OAUTH connection to Dropbox.  It's a call to the JS function dbxConnect()
        alert('here in dbxGetContents looking for ' + dbxFolderName);
        var dbxConn = dbxConnect();

        var dbxUrlTree = "https://api.dropbox.com/1/metadata/dropbox/" + dbxFolderName;     
        dbxUrlTree = dbxUrlTree + "?";
        dbxUrlTree = dbxUrlTree + dbxConn;

        jQuery.getJSON(dbxUrlTree,
            function(data){
                alert('here returning data');
                return data;
                }
            );
    }

非常感谢您的关注。

4

0 回答 0