昨天開始使用jQuery和jsTree插件,並通過對servlet的AJAX調用成功加載樹。現在,我想讓樹加載後打開所有節點,所以我向ajax屬性添加了成功函數。但是,我似乎無法使open_all()方法正常工作。我對使用jQuery非常陌生,所以我猜測這很簡單,我做錯了。爲什麼不jsTree open_all()爲我工作?
Firebug沒有顯示任何錯誤,這些錯誤排除了錯誤鍵入的方法名稱的愚蠢錯誤。我檢查了文檔,並且我認爲根據我閱讀的內容我正在做所有事情。樹正在正確加載,但不會在加載頁面後打開所有節點。
我在Firefox 3.6.8上使用jQuery 1.4.2和jsTree 1.0rc2。
下面是我使用加載樹,並試圖在樹打開所有節點的代碼:
// Create the tree object
$("td#modelXML").jstree({
core : { "animation" : 0 },
//xml_data : {"data" : "" + xml, "xsl" : "nest"},
xml_data : {"ajax" :
{"url" : "servlet/GetModelHierarchy",
"type" : "post", "data" : { modelId : "" + modelId} },
"xsl" : "nest",
"success" : function(){
$(this).open_all(-1);
}
},
themes : {"theme" : "classic", "dots" : true, "icons" : true},
types : {
"types" : {
"category" : {
"valid_children" : ["factor"]
},
"factor" : {
"valid_children" : ["level"]
},
"level" : {
"valid_children" : "none",
"icon" : {
"image" : "${request.contextPath}/jsTree/file.png"
}
}
}
},
plugins : ["themes", "types", "xml_data"]
});
+1此方法適用於我,接受的答案沒有。 – RedFilter 2012-02-01 17:05:33
無論如何,刷新後使這項工作?加載的事件似乎不會觸發。有沒有其他事件可以告訴數據何時加載? ('loaded.jstree',函數(事件,數據){ data.instance.open_node('0') })' – Jens 2012-08-24 04:43:05
)由於某些原因,這不適合我 – KeepCalmAndCarryOn 2014-03-25 03:21:58