无论何时用户单击文件夹旁边的[+],我都会通过json_data加载我的jsTree。我想要做的是将css类应用于某些节点,以便为用户突出显示它们。不是在讨论鼠标悬停或当前选定的节点,而是稍后人们必须查看的多个节点。相应的CSS类是已经从服务器JSON响应里面:在json_data加载后更改jsTree节点css类?
[
{"attr":{"id":"node_5","rel":"document","page_id":"4"},"data":"Test123","csscl":"ui-state-error","state":""},
{"attr":{"id":"node_6","rel":"folder","page_id":"6"},"data":"Services","csscl":"","state":"closed"}
]
我“Test123”节点应该得到一流“的UI状态错误”后面的树。 这里是我的jsTree:
$(function() {
// Settings up the tree. note to self: dont use the cookie plugin here, this will always overwrite pre-selected nodes
$("#jstree").jstree({
"plugins" : [ "themes", "json_data", "ui", "types", "hotkeys",],
"json_data" : {
"ajax" : {
"url" : "inc/tree_server.php",
"data" : function (n) {
return {
"operation" : "get_children",
"id" : n.attr ? n.attr("id").replace("node_","") : 1
};
},
success: function(n) {
for (var i in n)
{
jqid = "#"+n[i].attr["id"]+" a";
$(jqid).addClass(n[i].csscl);
}
}
}
},
// the UI plugin
"ui" : {
// selected onload
"initially_select" : [ "node_<?=$p->oTopic->iId;?>" ]
},
// the core plugin
"core" : {
"initially_open" : [ <?=$p->oTopic->sJstreeOpenSeq;?> ],
"animation" : 0
}
})
这是行不通的。我认为会发生的事情是,在树加载之后调用“success:function(n)”,但在绘制或准备好让JQuery找到所选节点并应用我的类之前调用它。 任何人都知道如何解决这个问题,或者在这种情况下,有更好的方法将css类应用于$(“#node5 a”)......?
你试过jsTree讨论组在http://groups.google.com/group/jstree? – Radek 2011-07-27 07:46:06
你可以将它设置在“数据”对象吗? “attr”:{“class”:“csscl”}?看看这里的第一个演示。 http://www.jstree.com/documentation/json_data – 2011-10-11 13:51:23