jstree의 클릭 이벤트에서 해당 node의 데이터 가져오는 방법이다.

data.a는 트리에 data에 넣어준 특정 변수값.


1
2
3
4
5
6
.bind('select_node.jstree'function(event, data){
    var id = data.instance.get_node(data.selected).id;        //id 가져오기
    var type = data.instance.get_node(data.selected).type;    //type 가져오기
    var path = data.instance.get_node(data.selected).path;    //paht 가져오기
    var a = data.instance.get_node(data.selected).data.a;    //data 에서 a 가져오기
})
cs


'jsTree' 카테고리의 다른 글

[jsTree]ajax로 jstree 생성 방법  (0) 2016.09.01

ajax로 데이터 가져와서 트리 생성하는 방법.

data array에서 data 부분은 트리의 노드가 가지고있어야 할 데이터를 마음대로 넣어줄수 있다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$.ajax({
    ...
    success: function(data){
        var data = new Array();
        $.each(data, function(idx, item){
            data[idx] = {id:item.id, parent:item.text, type:item.type, data:{a:item.a, b:item.b, ...}}; 
        });
 
        $("#tree").jstree({
            core: {
                data: data    //데이터 연결
            },
            types: {
                'default': {
                    'icon''jstree-folder'
                }
            },
            plugins: ['wholerow''types']
        })
        .bind('loaded.jstree'function(event, data){
            //트리 로딩 롼료 이벤트
        })
        .bind('select_node.jstree'function(event, data){
            //노드 선택 이벤트
        })
    }
});
cs


'jsTree' 카테고리의 다른 글

[jsTree] 클릭한 node의 id, type 등등 가져오는 방법  (0) 2016.09.02

+ Recent posts