2017-02-21 8 views
0

私は現在Dropbox APIで自分のフォルダを表示しようとしていますが、1つのフォルダしか表示されていませんがDropbox内に2つのフォルダがあります.. console.log(entry); reposnseが示されている2つのフォルダですが、私はjstreeのデータに関数を入れたときにのみ1つのフォルダが表示され、フォルダはあなたがjsTree世代を移動する必要がありますconsole.log(entry);jstreeで呼び出されたフォルダは1つだけです

var dbx = new Dropbox({ accessToken: access_token1 }); 
dbx.filesListFolder({ path: "" }) 
    .then(function(response) { 

    response.entries.forEach(function(entry) { 
     if (entry.tag == 'folder') { 
     entry.parent = '#' 
     } 
     entry.text = entry.name 
     console.log(entry); 
     console.log(entry.name); 

     $("#people").jstree({ 
     // generating tree from json data 
     "json_data": { 
      "data": { 
      "data": entry.name, 
      "state": "closed", 
      }, 

     }, 
     // plugins used for this tree 
     "plugins": ["json_data", "ui", "types", "crrm"] 
     }) 

     .bind("loaded.jstree", function() { 
      // do stuff when tree is loaded 
      $("#people").addClass("jstree-sugar"); 
      $("#people > ul").addClass("list"); 
      $("#people > ul > li > a").addClass("jstree-clicked"); 
     }) 
     .bind("select_node.jstree", function(e, data) { 
      // do stuff when a node is selected 
      data.inst.toggle_node(data.rslt.obj); 

     }); 
    }) 

    ///end of response 
    }) 
    .catch(function(error) { 
    console.log(error); 
    }); 

答えて

1

で最後reposnseありますレスポンス反復処理から外してください。そうしないと、ツリー内の最後のフォルダのみが常に表示されます。

jsTree v3を使用していない場合は、次のコードを使用できます。デモ - Fiddle Demoもチェックしてください。

var dbx = new Dropbox({ accessToken: access_token1 }); 
dbx.filesListFolder({ path: "" }) 
    .then(function(response) { 

    var nodes = []; // store the nodes 

    response.entries.forEach(function(entry) { 
     if (entry.tag == 'folder') { 
     entry.parent = '#' 
     } 

     // add nodes to array - you will also need id for every node 
     // to properly map files to folders in the tree 
     nodes.push({ 
     id: entry.id, 
     parent: entry.parent, 
     text: entry.name 
     }); 

     console.log(entry); 
     console.log(entry.name); 
    }) 

    // tree config out of the response iteration 
    $("#people").jstree({ 
     // generating tree from json data 
     "core": { 
      "data": nodes // pass nodes to tree config 
      } 
     }, 
     // plugins used for this tree 
     "plugins": ["json_data", "ui", "types", "crrm"] 
     }) 
     .on("loaded.jstree", function() { 
     // do stuff when tree is loaded 
     $("#people").addClass("jstree-sugar"); 
     $("#people > ul").addClass("list"); 
     $("#people > ul > li > a").addClass("jstree-clicked"); 
     }) 
     .on("select_node.jstree", function(e, data) { 
     // do stuff when a node is selected 
     data.inst.toggle_node(data.rslt.obj); 

     }); 


    ///end of response 
    }) 
    .catch(function(error) { 
    console.log(error); 

    }); 
関連する問題