2017-02-21 26 views
0

我目前正在嘗試jstree列出我的Dropbox API中的文件夾,但只有1個文件夾正在顯示,但我必須在我的Dropbox中2個文件夾..但是,當我安慰功能console.log(entry);該reposnse正在顯示的2個文件夾,但是當我把函數的jstree只有1個文件夾是顯示和文件夾的數據是在console.log(entry);只有1個文件夾在jstree中調用

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代在響應迭代之外,否則您總是隻能看到樹中的最後一個文件夾。

如果您使用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); 

    }); 
相關問題