jsTree獲取選中節點和選中指定節點


jstree獲取當前選中的checkbox和獲取選中節點的所有節點

首先初始化一個帶有復選框的 jstree

$('#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'],
});

jstree獲取當前選中節點

這時分為兩種選中,一個是點擊也就是鼠標單擊 節點 而不是 checkbox 的選中

var treeNode = $('#demo_tree').jstree(true).get_selected(true); //獲取所有選中的節點對象

 同理獲取 checkbox 的選中

var treeNode = $('#demo_tree').jstree(true).get_checked(true); //獲取所有 checkbox 選中的節點對象

jstree選中指定的節點

// id 是選中的節點 id,然后后面的一個參數 true 表示的是不觸發默認select_node.change的事件
var id = 'ajson1';
$('#schema_tree').jstree('select_node', id , true);

checkbox 同理。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM