jstree("getchecked",null,true) . each not a function! typeerror

883 views
Skip to first unread message

Elkiscoming

unread,
Sep 5, 2014, 7:21:01 AM9/5/14
to jst...@googlegroups.com
I just downloaded jstree... and I have a type error
here is all my code, all I linked and etc...
<html>
    <head>
        <script src="dist/libs/jquery.js"></script>
        <link rel="stylesheet" href="dist/themes/default/style.min.css" />
        <script src="dist/jstree.min.js"></script>
    </head>
    <body>
        <div id="tree1" data-url="/nodes/">
            <ul>
                <li id="good">Root node 1
                <ul id="hei">
                    <li id="2">Child node 1</li>
                    <li id="3"><a href="#">Child node 2</a></li>
                </ul>
                </li>
            </ul>
        </div>
        <input type="text" name="jsfields" id="jsfields" value="" />
        <input type="submit" onclick="submitMe()" value="submit" />

        <script type="text/javascript">
            $(function () { $('#tree1').jstree({'plugins':["checkbox" , "themes", "html_data"]}); });
            function submitMe() {
                var checked_ids = [];
                checked = $('#tree1').jstree("get_checked",null,true);
                checked.each(function(){
                    checked_ids.push(this.id);
                });
                //setting to hidden field
                console.log("hei");
                document.getElementById('jsfields').value = checked_ids.join(",");
            }
        </script>
    </body>
</html>


I will recive: TypeError: checked.each is not a function on line 54...
can anybody help me?

Ivan Bozhanov

unread,
Sep 5, 2014, 5:09:10 PM9/5/14
to jst...@googlegroups.com
get_checked does not return an array of jQuery nodes, but a normal array - that is clearly stated in the API docs.

What you need (an array of IDs can be accomplished like this:
...
var checked_ids - $('#tree_1').jstree('get_checked'); // everything after this is not needed
console.log("hei");

Best regards,
Ivan
Reply all
Reply to author
Forward
0 new messages