JsTree使用一例

        SearchDesignPatent.treeContainer().jstree({
            'core' : {
                'data' : json.data
            },
        }).bind('click.jstree', function(event) {
            var eventNodeName = event.target.nodeName;
               if (eventNodeName == 'INS') {
                   return;
               } else if (eventNodeName == 'A') {
                var $subject = $(event.target).parent();
                //有Bug,非叶子节点未展开前,下面条件也成立
                if ($subject.find('ul').length > 0){
                    alert("请选择叶子节点");
                } else {
                if(window.console){
                    console.log($subject.text());
                    console.log($subject.attr("id"));
                    console.log($("input[name='type']").val());
                    $("input[name='type']").val($subject.attr("id"));
                }
                 }
               }
           }).on('changed.jstree', function(e, data) {
            r = [];  
            var i, j;  
            for (i = 0, j = data.selected.length; i < j; i++) {  
                var node = data.instance.get_node(data.selected[i]);  
                if (data.instance.is_leaf(node)) {  
                    r.push(node.id);
                    alert("叶子");
                }else{
                    alert("节点");
                }
            }
        });

 

posted @ 2016-05-30 18:27  任国强  阅读(672)  评论(0编辑  收藏  举报