Question

I am unable to get the jsTree "Types" plugin to work in any capacity at all, and there are no errors firing anywhere that I can detect.

1.) I referred to this SO Question to have the node open/close with a mouseclick, but the function does not ever get executed.

2.) For the "Types" plugin the jsTree Plugin Documentation says this:

To set a node's type you can use set_type or supply a type property with the node's data.

I suspect it's a setup problem because neither of the "Types" settings are working, yet the "contextmenu" plugin does work, so it appears all the scripts are in place and I'm doing something wrong for "Types"

Has anyone else encountered this, or does anyone see where I'm going wrong?

HTML

<div id="jstree"></div>
<script>
    $(function () {
        $('#jstree').jstree({
            "types" : {
                "types" : {
                    "series_type" : {
                        "icon" : {
                            "image" : "images/seriesnode.png"
                        }
                    },
                    "default" : {
                        "select_node" : function(e) {
                            console.info(e);
                            this.toggle_node(e);
                            return false;
                        }
                    }
                }
            },
            "plugins" : [ "types", "ui" , "contextmenu" ],
            "contextmenu": { "items": {} },
            "core" : {
                'data' : {
                    'url' : 'series_tree_data.php'
                }
            }
        });
    });
</script>

JSON data returned from AJAX call:

[
    {   "id":"series_123120",
        "parent":"#",
        "text":"1945 - The Year That Changed The World",
        "type":"series_type",
        "state":{"opened":true}
    },
    {   "id":"title_2003150",
        "parent":"series_123120",
        "text":"Beginning of the End",
    },
    {   "id":"segment_3006200",
        "parent":"title_2003150",
        "text":"Full Program",
    },
    {   "id":"file_552973",
        "parent":"segment_3006200",
        "text":"1945_part_1.flv",
        "icon":false
    }
]
Was it helpful?

Solution

From what I see in the documentation at http://www.jstree.com/api/#/?f=$.jstree.defaults.types , theres no mention of "select_node", so it would seem that portion should not work at all. I'd check to see if you have the latest library.

OTHER TIPS

I had some trouble with the types, this worked for me:

$('#jstree').jstree({
                "types":{
                   "key" : {
                       "icon": "Content/Images/skey.png"
                    },
                   "value": {
                       "icon": "Content/Images/sValue.png"
                   }
                },

you might also want to play around with adding a_attr: "rel": "series_type" to your data.

good luck

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top