tags:

views:

57

answers:

1

Hello,

I am new to jsTree and am having problems with a very simple example.

My html:

<ul id='categories'>
    <li><a href"/Browse/1">Category 1</a>
        <ul>
            <li><a href="/Browse/3">Subcategory 1.1</a></li>
        </ul>
    </li>
    <li><a href="/Browse/2">Category 2</a>
        <ul>
            <li><a href="/Browse/4">Subcategory 2.1</a></li>
        </ul>
    </li>
</ul>

Code:

<script type='text/javascript'>
    $(document).ready(function() {
    $('#categories').jstree({ 'plugins' : 'html_data' });
});
</script>

Error:

Line: 1694
Error: Exception thrown and not caught

It appears as though jsTree is trying to call the cookie plugin which I do not have installed.

In my case, I do not need or want cookies.

How can I run jsTree without them?

UPDATE:

I tried this plus various combinations of plugins:

<script type='text/javascript'>
  $(document).ready(function() {
  $.jstree.defaults.plugins = ['ui', 'crrm', 'themes', 'html_data'];
  $('#categories').jstree();
});
</script>

The result now is a blank page. The error has gone away though.

Thank you,

Rick

+1  A: 

If you look at line 1755, the cookies plugin is being used by default:

// include cookies by default
$.jstree.defaults.plugins.push("cookies");

To remove it your option must be an array so it overrides rather than adds to the defaults, like this:

$('#categories').jstree({ 'plugins' : ['ui', 'crrm', 'themes', 'html_data'] });

This includes the others that are added by default, just remove any you don't want.

Also the structure needs a bit of a change for html_data to work, like this:

<div id="categories">
    <ul>
        <li><a href="#">Category 1</a></li>
        <li><a href="#">Category 2</a></li>
    </ul>
</div>

Note the addition of the parent element and the anchors. You can give it a try here. ​

Nick Craver
I changed it to "$('#categories').jstree({ 'plugins' : ['html_data'] });", but now the page comes up blank. Are there other options that I need to specify? At this stage, I do not need any themes or anything fancy.
rboarman
@rboarman - You need at least `ui`, I put in the answer all the default ones, you can remove what you don't want...though even the default theme is a theme, so I'm not sure how it behaves without the `theme` plugin at all.
Nick Craver
I tried "ui, html_data" and "ui, html_data, themes" without luck. Nothing gets displayed. At least I don't get an error any more. :)
rboarman
@rboarman - What if you do `$.jstree.defaults.plugins = ['ui', 'crrm', 'themes', 'html_data'];` before calling `.jstree()`? Just for kicks give this a try, not where I can test at the moment. Make sure it's an array and that each item is in quotes, it shouldn't be a single string.
Nick Craver
Same thing. I'll update my post with the exact code as it stands now.
rboarman
@rboarman - The structure is the issue now...checkout the updated answer and demo for a fix :)
Nick Craver
I updated my post again to show my updated markup; the structure seems to be okay doesn't it? Thanks for your help by the way.
rboarman
It somehow started working without the parent <div>. Thanks again!
rboarman
jsFiddle is pretty cool by the way. Thanks for the tip.
rboarman
@rboarman - welcome :)
Nick Craver