2017-02-21 3 views
0

현재 Dropbox API에서 내 폴더를 나열하려고 jstree를 시도하고 있지만 폴더 1 개만 표시되지만 내 보관 상자에는 2 개의 폴더가 있습니다 .. 그러나 기능을 콘솔에 연결하면 console.log(entry); reposnse가 표시되는 2 개 폴더,하지만 난 단지 1 폴더 표시 및 폴더되고있는 jstree의 데이터 기능을 넣을 때 당신은 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); 

    });