Q&A
前提・実現したいこと
jsTreeでtreeを表示しているのですが、ファイルのみ表示されている状態です。
ファイルのみではなく、ファイル名も表示したいです。
ファイル名はJSONデータに格納しております。
発生している問題・エラーメッセージ
ファイルのみ表示される。
該当のソースコード
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.2/themes/default/style.min.css"> <script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.2/jstree.min.js"></script> </head> <body> <input id="search" type="button" value="検索" /> <div id="jstree"></div> <script type="text/javascript"> let data; $('#search').click(function() { let hostUrl = "http://localhost:3000/hits"; $.ajax({ type: 'get', url: hostUrl, dataType : 'json' }).done(function(data){ console.log("success"); $(function () { $('#jstree').jstree({ 'core': { 'data': { 'url': hostUrl, // ajaxで読み込むjsonファイル 'dataType': 'json', 'data': function (node) { data= node.id; console.log(data); return { 'id': node.id }; } } } }) } ); }).fail(function(){ alert('データが無いです'); $('#zip').val(""); }); }); </script> </body> </html>
JSON
1{ 2 "hits": [ 3 { 4 "groupId": 1, 5 "parentGroupId": "", 6 "itemCode": "", 7 "itemName": "テスト1", 8 "sortOrder": 1 9 }, 10 { 11 "groupId": 2, 12 "parentGroupId": "", 13 "itemCode": "", 14 "itemName": "テスト2", 15 "sortOrder": 2 16 }, 17 { 18 "groupId": 3, 19 "parentGroupId": "", 20 "itemCode": "", 21 "itemName": "テスト3", 22 "sortOrder": 3 23 }, 24 { 25 "groupId": 9, 26 "parentGroupId": "1", 27 "itemCode": "", 28 "itemName": "テスト1-1", 29 "sortOrder": 1 30 }, 31 { 32 "groupId": 11, 33 "parentGroupId": "1", 34 "itemCode": "", 35 "itemName": "テスト1-2", 36 "sortOrder": 7 37 }, 38 { 39 "groupId": 14, 40 "parentGroupId": "1", 41 "itemCode": "", 42 "itemName": "テスト1-3", 43 "sortOrder": 12 44 }, 45 { 46 "groupId": 13, 47 "parentGroupId": "1", 48 "itemCode": "", 49 "itemName": "テスト1-4", 50 "sortOrder": 12 51 }, 52 { 53 "groupId": 1029, 54 "parentGroupId": "9", 55 "itemCode": "10", 56 "itemName": "テスト結果10", 57 "sortOrder": 2 58 }, 59 { 60 "groupId": 1026, 61 "parentGroupId": "9", 62 "itemCode": "20", 63 "itemName": "テスト結果20", 64 "sortOrder": 7 65 }, 66 { 67 "groupId": 1031, 68 "parentGroupId": "9", 69 "itemCode": "30", 70 "itemName": "テスト結果30", 71 "sortOrder": 11 72 }, 73 { 74 "groupId": 1076, 75 "parentGroupId": "9", 76 "itemCode": "", 77 "itemName": "テスト9-1", 78 "sortOrder": 18 79 } 80 ] 81}
試したこと
公式のドキュメントを読んだのですが、見つけることが出来ませんでした。。
補足情報(FW/ツールのバージョンなど)
OS:Mac
回答1件
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
2021/04/08 00:30
2021/04/08 00:37
2021/04/08 00:42
2021/04/08 00:47