2012-03-12 4 views
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">&nbsp;</ins><a class="" href="#"><ins class="jstree-icon">&nbsp;</ins>root</a><ul style=""><li class="jstree-closed" id="Photography"><ins class="jstree-icon">&nbsp;</ins><a class="" href="#"><ins class="jstree-icon">&nbsp;</ins>Photography</a><ul><li class="jstree-last jstree-closed" id="Lenses"><ins class="jstree-icon">&nbsp;</ins><a href="#"><ins class="jstree-icon">&nbsp;</ins>Lenses</a><ul><li class="jstree-leaf" id="Telephoto"><ins class="jstree-icon">&nbsp;</ins><a href="#"><ins class="jstree-icon">&nbsp;</ins>Telephoto</a></li><li class="jstree-leaf" id="Macro"><ins class="jstree-icon">&nbsp;</ins><a href="#"><ins class="jstree-icon">&nbsp;</ins>Macro</a></li><li class="jstree-last jstree-leaf" id="Other"><ins class="jstree-icon">&nbsp;</ins><a href="#"><ins class="jstree-icon">&nbsp;</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 

答えて

1

イベントによっては、data.rsltオブジェクトが入力されないことがあります。
jsTree core documentationのとおり

データ構造:特に

{ 
    "inst" : /* the actual tree instance */, 
    "args" : /* arguments passed to the function */, 
    "rslt" : /* any data the function passed to the event */, 
    "rlbk" : /* an optional rollback object - it is not always present */ 
} 

追加のデータが関数に渡されなかったため、loaded.jstreeイベントは空data.rsltを有するであろう。

create.jstreeまたはrename.jstreeのような他のイベントでは、data.rsltが入力されます。

私はそれがあなたに今より明らかになることを望みます:-)

+0

ありがとう、あなたの権利と私は今働いています。 私はもう少し読んでいたはずです。 – Chris

+0

私は今この問題に数時間を費やしてきましたが、この答えは私のために何も解決していません。私はここからajaxデモをフォローしています:http://www.jstree.com/demo/open_closeそして、addBack機能についてのエラーを取得しています。さらに、ajaxデータ関数に渡される 'n'オブジェクトにはattr( "id")値がありません。したがって、この畳んだ動物園を使ってクリックしたアイテムのIDを取得する必要があります:$(n [0])。find "a")。attr( "id")。 – tufelkinder

関連する問題