jquery - Populate jsTree from external JSON file -
i've been experimenting jquery.jstree library , need help. please advise me on how read json_data
external .json
file.
$("#treedemo").jstree({ "plugins" : [ "themes", "json_data", "ui", "types" ], //"json_data": { // "ajax" : { // "url" : "series.json" // } //}, "json_data" : { "data" : [{"data":"series 1","children":[{"data":"season 1","children":[{"data":"episode 1.avi","attr":{"rel":"file"}},{"data":"episode 2.avi","attr":{"rel":"file"}},{"data":"episode 3.avi","attr":{"rel":"file"}}],"attr":{"rel":"folder"}},{"data":"season 2","children":[{"data":"episode 4.avi","attr":{"rel":"file"}},{"data":"episode 5.avi","attr":{"rel":"file"}}],"attr":{"rel":"folder"}}],"attr":{"rel":"folder"}},{"data":"series 2","children":[{"data":"season 1","children":[{"data":"episode 1.avi","attr":{"rel":"file"}},{"data":"episode 2.avi","attr":{"rel":"file"}},{"data":"episode 3.avi","attr":{"rel":"file"}},{"data":"episode 4.avi","attr":{"rel":"file"}}],"attr":{"rel":"folder"}}],"attr":{"rel":"folder"}},{"data":"series 3","children":[{"data":"episode 1.avi","attr":{"rel":"file"}},{"data":"episode 2.avi","attr":{"rel":"file"}}],"attr":{"rel":"folder"}},{"data":"series 1","children":[{"data":"episode 1.avi","attr":{"rel":"file"}}],"attr":{"rel":"folder"}},{"data":"series 2","children":[{"data":"episode 1.avi","attr":{"rel":"file"}},{"data":"episode 2.avi","attr":{"rel":"file"}}],"attr":{"rel":"folder"}}] }, "types" : { "max_depth" : -2, "max_children" : -2, "valid_children" : ["drive"], "types" : { "folder" : { "valid_children" : ["default", "folder"], "icon" : { "image" : "images/folder.png" } }, "file" : { "valid_children" : "none", "icon" : { "image" : "images/file.png" } } } }, "themes" : { "theme" : "default", "url" : "themes/default/style.css", "dots" : true, "icons" : true }, "search" : { "case_insensitive" : true, "ajax" : { "url" : "/static/v.1.0pre/_docs/_search_result.json" } } })
so above code works jstree should. commented json_data
plugin suppose read exact same json data specified 'series.json' file however, when code run, loading gif displayed.
please help.
thanks in advance, grant
this seems common issue. anyways, make ajax
call fetch required json file shown below.
"json_data":{ "ajax" : { "url" : "info.json" // url fetch data. use relative url if required } }
this work!
cheers!
Comments
Post a Comment