jsTree 3 and checkbox

323 views
Skip to first unread message

Sanyi

unread,
Feb 6, 2014, 8:46:31 AM2/6/14
to jst...@googlegroups.com
Hi,
I am using jsTree3 with the checkbox plugin and data is loaded through Ajax call.
The jQuery 1.9.1 throws the 'Script is busy or stopped responding' error in Firefox when:
1. I try to select the all leaves of a node by clicking on it.
2. I try to select the all leaves of a node one by one.
    (The error arises at the last one selection.)

I have checked the DOM in Firebug and everything looks  perfect.
Can you help me in this problem, please.

Ivan Bozhanov

unread,
Feb 6, 2014, 8:48:47 AM2/6/14
to jst...@googlegroups.com
How large is the tree? And are your IDs unique (if you pass in node IDs yourself).

Best regards,
Ivan

Sanyi

unread,
Feb 6, 2014, 9:00:24 AM2/6/14
to jst...@googlegroups.com
The root has 17 nodes. When I select the leaves one by one it works in case of 2 leaves but it crashes at 8 leaves.
Thank you.

Sanyi

unread,
Feb 6, 2014, 9:29:02 AM2/6/14
to jst...@googlegroups.com
And the IDs are unique.

Ivan Bozhanov

unread,
Feb 6, 2014, 2:21:07 PM2/6/14
to jst...@googlegroups.com
I will need to see your config and data. Also make sure you do not bind to any events - so that we eliminate external factors.

Sanyi

unread,
Feb 6, 2014, 4:51:40 PM2/6/14
to jst...@googlegroups.com
This is a subtree what is loaded by Ajax. Clicking on User C the Firefox gives the error in http://localhost:49437/Scripts/jquery-1.9.1.js:5146. The location of the error is always different.
The error appears always before jsTree events.
[
  {
    "children": [
      {
        "children": null,
        "id": "615365ab-8295-4b5c-aef2-9dfc35a13d35",
        "text": "User A",
        "icon": "/Content/jsTree/boss.png",
        "state": {
          "opened": false,
          "disabled": false,
          "selected": true,
          "undetermined": false
        },
        "_parent_": null,
        "li_attr": null,
        "a_attr": {
          
        }
      },
      {
        "children": null,
        "id": "81a30d6a-2a82-40c2-9a6d-3acd8d4b576a",
        "text": "User B",
        "icon": null,
        "state": {
          "opened": false,
          "disabled": false,
          "selected": true,
          "undetermined": false
        },
        "_parent_": null,
        "li_attr": null,
        "a_attr": {
          
        }
      },
      {
        "children": null,
        "id": "a138853c-539d-467d-ad51-2a5752e198f6",
        "text": "User C",
        "icon": null,
        "state": {
          "opened": false,
          "disabled": false,
          "selected": false,
          "undetermined": false
        },
        "_parent_": null,
        "li_attr": null,
        "a_attr": {
          
        }
      },
      {
        "children": null,
        "id": "b188b538-bda9-4dd0-bf42-e1d75ed40284",
        "text": "User D",
        "icon": null,
        "state": {
          "opened": false,
          "disabled": false,
          "selected": true,
          "undetermined": false
        },
        "_parent_": null,
        "li_attr": null,
        "a_attr": {
          
        }
      },
      {
        "children": null,
        "id": "87a919ab-7c66-4222-b9a0-880dea4b2226",
        "text": "User E",
        "icon": null,
        "state": {
          "opened": false,
          "disabled": false,
          "selected": true,
          "undetermined": false
        },
        "_parent_": null,
        "li_attr": null,
        "a_attr": {
          
        }
      },
      {
        "children": null,
        "id": "0947fb5a-c224-431d-8b83-6aae8a409311",
        "text": "User F",
        "icon": null,
        "state": {
          "opened": false,
          "disabled": false,
          "selected": true,
          "undetermined": false
        },
        "_parent_": null,
        "li_attr": null,
        "a_attr": {
          
        }
      },
      {
        "children": null,
        "id": "66df86a6-d1f7-475b-a11d-44394163f06e",
        "text": "User G",
        "icon": null,
        "state": {
          "opened": false,
          "disabled": false,
          "selected": true,
          "undetermined": false
        },
        "_parent_": null,
        "li_attr": null,
        "a_attr": {
          
        }
      },
      {
        "children": null,
        "id": "_e0bf4d1e-4f34-4c20-9ccf-7ac40c2ee522",
        "text": "User H",
        "icon": "/Content/jsTree/boss.png",
        "state": {
          "opened": false,
          "disabled": false,
          "selected": true,
          "undetermined": false
        },
        "_parent_": null,
        "li_attr": null,
        "a_attr": {
          "class": "disabled couser",
          "rel": "nochb"
        }
      }
    ],
    "id": "31",
    "text": "Department",
    "icon": "/Content/jsTree/dep.png",
    "state": {
      "opened": false,
      "disabled": false,
      "selected": false,
      "undetermined": false
    },
    "_parent_": null,
    "li_attr": null,
    "a_attr": {
      "class": "strong"
    }
  }
]

The config:
$("#maintree")
    .on("open_node.jstree"function (e, data) {
        $('div#maintree li > a[rel="nochb"] i.jstree-checkbox').remove();
        $('i.jstree-themeicon-custom').css("background-size"'16px 16px');
    })
    .on("load_node.jstree"function (e, data) {
        $('div#maintree li > a[rel="nochb"] i.jstree-checkbox').remove();
        $('i.jstree-themeicon-custom').css("background-size"'16px 16px');
    })
    .on("changed.jstree"function (e, data) {
        if (data.node != undefined) {
            console.log($("li#" + data.node.id).parents().eq(1).attr("id"));
            if ($('div#maintree li#' + data.node.id + ' > a').hasClass('disabled')) {
                $('div#maintree').jstree("select_node"'#' + data.node.id);
            }
            else {
                $.ajax({
                    type: "GET",
                    url: SetMyUser,
                    cache: false,
                    data: { user: data.node.id,
                        node: (data.node.children.length == 0 ? $("li#" + data.node.id).parents().eq(1).attr("id") : data.node.id),
                        state: (data.action == 'select_node'),
                        children: JSON.stringify(data.node.children)
                    }
                }).success(function (result) {
                }).error(function (xhr, status, message) {
                });
            }
        }
    })
    .jstree({
        "core": {
            "data": {
                "url": GetTreeData,
                'data'function (node) {
                    return { 'id'node.id === '#' ? 0 : node.id };
                }
            },
            'strings': {
                'Loading ...''Betöltés ...'
            },
            'animation'false
        },
        "plugins": ['checkbox']
    });
Thank you to look at.

Ivan Bozhanov

unread,
Feb 6, 2014, 8:14:52 PM2/6/14
to jst...@googlegroups.com
I am 99% sure without running it that you are causing an endless loop by doing this:
    .on("changed.jstree"function (e, data) {
            if ($('div#maintree li#' + data.node.id + ' > a').hasClass('disabled')) {
                $('div#maintree').jstree("select_node"'#' + data.node.id);
            }

Remove this handler and see if you still get the error. Basically you when something is selected, you trigger another select, which in turn triggers changed, and so on. In fact - remove all ".on" handlers and only leave .jstree(... - that is the only way to check if jstree is causing the issue or your code.

Best regards,
Ivan

Sanyi

unread,
Feb 7, 2014, 2:18:58 AM2/7/14
to jst...@googlegroups.com
I have left all events out, but the same erro and this error arises at only one node, when I want to open it.
Clicking on the node to open it, the request goes to the server, the server sends back the valid json and jQuery throws the error.

Sanyi

unread,
Feb 7, 2014, 3:10:33 AM2/7/14
to jst...@googlegroups.com
The node problem is solved,
I do not understand the cause of it but when I cleared two concerned tables the node turned opening.

Best regards,
Sanyi

Sanyi

unread,
Feb 7, 2014, 5:53:52 AM2/7/14
to jst...@googlegroups.com
Dear Ivan,

Finally I found out the problem.
When I opened a node the returned Json contained also the opened node not only its children.
Thank you very much for your help.

Best regards,
Sanyi

Ivan Bozhanov

unread,
Feb 7, 2014, 8:27:35 AM2/7/14
to jst...@googlegroups.com
Glad you worked it out - sorry I could not help much :)
Reply all
Reply to author
Forward
0 new messages