最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get changing item's ids in jstree change event - Stack Overflow

programmeradmin2浏览0评论

I want to know which items checked or unchecked when it's changed.

var MenuTree = function () {
    $.ajax({
        type: "POST",
        url: "Menu_Permission.aspx/Menu",
        contentType: "application/json",
        dataType: "json",
        success: function (data) {
            var menujson = JSON.parse(data.d);
            $('#tree_menu').jstree({
                'plugins': ["wholerow", "checkbox", "types"],
                'core': {
                    "themes": {
                        "responsive": false
                    },
                    'data': menujson
                }
            });
        },
        error: function () {
            console.log('err')
        }
    });

    $(function () {
        $('#tree_menu').on('changed.jstree', function (e, data) {
            console.log(data.node);
            console.log(data.selected);
        });
    });

    $(function () {
        $('#tree_menu').on('deselect_node.jstree Event', function (e, data) {
            console.log(data.node.id);
        });
    });
    $(function () {
        $('#tree_menu').on('select_node.jstree Event', function (e, data) {
            console.log(data.node.id);
        });
    });


}

I have these functions and changed.jstree returns object and I cannot reach the id which is clicked. Others return me id exactly but, if it is the last checked item and it changes, How will I know parents checkbox is changed or not. Otherwise if it is the root item and it has children, all of them will gone and how can I know it. data.selected returns me array of selected but is there any way to know which is changed, from slected to to unselected or reverse?

And the functions fire onload, how can I change it?

I want to know which items checked or unchecked when it's changed.

var MenuTree = function () {
    $.ajax({
        type: "POST",
        url: "Menu_Permission.aspx/Menu",
        contentType: "application/json",
        dataType: "json",
        success: function (data) {
            var menujson = JSON.parse(data.d);
            $('#tree_menu').jstree({
                'plugins': ["wholerow", "checkbox", "types"],
                'core': {
                    "themes": {
                        "responsive": false
                    },
                    'data': menujson
                }
            });
        },
        error: function () {
            console.log('err')
        }
    });

    $(function () {
        $('#tree_menu').on('changed.jstree', function (e, data) {
            console.log(data.node);
            console.log(data.selected);
        });
    });

    $(function () {
        $('#tree_menu').on('deselect_node.jstree Event', function (e, data) {
            console.log(data.node.id);
        });
    });
    $(function () {
        $('#tree_menu').on('select_node.jstree Event', function (e, data) {
            console.log(data.node.id);
        });
    });


}

I have these functions and changed.jstree returns object and I cannot reach the id which is clicked. Others return me id exactly but, if it is the last checked item and it changes, How will I know parents checkbox is changed or not. Otherwise if it is the root item and it has children, all of them will gone and how can I know it. data.selected returns me array of selected but is there any way to know which is changed, from slected to to unselected or reverse?

And the functions fire onload, how can I change it?

Share Improve this question asked Mar 19, 2014 at 13:59 user3436421user3436421 231 gold badge1 silver badge6 bronze badges 1
  • Can you provide a jsfiddle or jsbin with a specific example of what you expect? – Phil H Commented Mar 26, 2014 at 14:25
Add a ment  | 

1 Answer 1

Reset to default 3

Use following:

$(function () {
    $('#tree_menu').on('changed.jstree', function (e, data) {
        console.log(data.node.id);
    });
});

Instead of

console.log(data.node);

Use

console.log(data.node.id);
发布评论

评论列表(0)

  1. 暂无评论