1
jsTreeを使用すると、データオブジェクトを読み込もうとするとdata.rsltが未定義になります。jsTreeでdata.rsltが未定義です
JSONをロードするツリーを作成するjQueryがあり、読み込んだときにdata.rsltオブジェクトをコンソールに出力する必要があります。ここで
$(function() {
$("#demo1").jstree({
"plugins" : [ "themes","json_data","ui", "crrm" ],
"json_data" : {
"ajax" : {
"url" : "categorytreejson.asp"
}
},
"ui" : {
"initially_select" : [ "root" ]
}
});
$("#demo1").bind("loaded.jstree", function (e, data) {
console.log(data.rslt)
});
});
は、JSONデータ
{"data": "root", "attr": {"id": "root"}, "children": [{"data": "Photography", "attr": {"id": "Photography"}, "children": [{"data": "Lenses", "attr": {"id": "Lenses"}, "children": [{"data": "Telephoto", "attr": {"id": "Telephoto"}},{"data": "Macro", "attr": {"id": "Macro"}},{"data": "Other", "attr": {"id": "Other"}}]}]}]}
結果のHTML
<li class="jstree-last jstree-open" id="root"><ins class="jstree-icon"> </ins><a class="" href="#"><ins class="jstree-icon"> </ins>root</a><ul style=""><li class="jstree-closed" id="Photography"><ins class="jstree-icon"> </ins><a class="" href="#"><ins class="jstree-icon"> </ins>Photography</a><ul><li class="jstree-last jstree-closed" id="Lenses"><ins class="jstree-icon"> </ins><a href="#"><ins class="jstree-icon"> </ins>Lenses</a><ul><li class="jstree-leaf" id="Telephoto"><ins class="jstree-icon"> </ins><a href="#"><ins class="jstree-icon"> </ins>Telephoto</a></li><li class="jstree-leaf" id="Macro"><ins class="jstree-icon"> </ins><a href="#"><ins class="jstree-icon"> </ins>Macro</a></li><li class="jstree-last jstree-leaf" id="Other"><ins class="jstree-icon"> </ins><a href="#"><ins class="jstree-icon"> </ins>Other</a></li></ul></li></ul></li></li></ul></li></ul></li>
そしてFirebugの中のデータオブジェクトです。
args: []
inst: Object { data={...}, get_settings=function(), _get_settings=function(), more...}
rlbk: false
rslt: undefined
ありがとう、あなたの権利と私は今働いています。 私はもう少し読んでいたはずです。 – Chris
私は今この問題に数時間を費やしてきましたが、この答えは私のために何も解決していません。私はここからajaxデモをフォローしています:http://www.jstree.com/demo/open_closeそして、addBack機能についてのエラーを取得しています。さらに、ajaxデータ関数に渡される 'n'オブジェクトにはattr( "id")値がありません。したがって、この畳んだ動物園を使ってクリックしたアイテムのIDを取得する必要があります:$(n [0])。find "a")。attr( "id")。 – tufelkinder