jstree提供了一些默认选中的api,但是能起作用的很少,这里介绍一种手动选中节点的方法。`
var selectByDefault = function(){
//给jstree添加ready事件,必须在jstree准备好之后再去修改,否则无法成功
//$("#jstree")是jstree容器,即我们初始化jstree的jQuery选择器
$("#jstree").on("ready.jstree",function(){
if(currentBoardId==""||currentBoardId==null){
return;
}
var boardId = currentBoardId.split("'")[1];
//在该node的li包装层修改其属性值。
$("#"+boardId).attr('aria-selected',true);
//在该node的a标签处加入class修改其样式
$("#"+boardId+" a").addClass("jstree-clicked");
//手动向jstree维护的select数组添加值,以便于可以使用get_selected取到所选node
//如果没有这一句,是无法用jstree的api取到当前选中node,前面所做的就没有意义了
$("#jstree").jstree()._data.core.selected.push(boardId);
});
};`