Search code examples
dynatree

Dynatree - Where can I store additional info in each node?


I am currently testing out Dynatree and I just want to ask if there is an available property/parameter in which I can store additional info (like property 'value' in ASP.NET TreeView) for each node? Thanks in advance.


Solution

  • You can add custom properties using HTML with the data attribute (works, although a validator might complain.)

    For example add a new url property:

    <ul>
        <li data="url: 'http://jquery.com'">jQuery home
        <li data="url: 'http://docs.jquery.com'">jQuery docs
    

    Or when loading from JSON or JS objects:

    children: [
        { title: "jQuery home", url: "http://jquery.com" },
        { title: "jQuery docs", url: "http://docs.jquery.com" },
    

    After that, you can access it like so:

    onActivate: function(node) {
        if( node.data.url )
            window.open(node.data.url);
        $("#echoActive").text(node.data.title);
    },
    

    EDIT: Starting with release 1.2 <a> tags are natively supported ( How to make hyperlinks in dynaTree jQuery plugin clickable? ).