jstree獲取當前選中的checkbox和獲取選中節點的全部節點node
首先初始化一個帶有複選框的 jstreejson
$('#demo_tree').jstree({ "core" : { 'data': [ { "id" : "ajson1", "parent" : "#", "text" : "Simple root node"}, { "id" : "ajson2", "parent" : "#", "text" : "Root node 2" }, { "id" : "ajson3", "parent" : "ajson2", "text" : "Child 1" }, { "id" : "ajson4", "parent" : "ajson2", "text" : "Child 2" }, ] }, "plugins" : ['checkbox'], });
這時分爲兩種選中,一個是點擊也就是鼠標單擊 節點 而不是 checkbox 的選中spa
var treeNode = $('#demo_tree').jstree(true).get_selected(true); //獲取全部選中的節點對象
同理獲取 checkbox 的選中code
var treeNode = $('#demo_tree').jstree(true).get_checked(true); //獲取全部 checkbox 選中的節點對象
// id 是選中的節點 id,而後後面的一個參數 true 表示的是不觸發默認select_node.change的事件 var id = 'ajson1'; $('#schema_tree').jstree('select_node', id , true);
checkbox 同理。對象