Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

dynatree

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.

like image 710
SajmiraZ Avatar asked May 16 '11 02:05

SajmiraZ


1 Answers

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? ).

like image 80
mar10 Avatar answered Oct 15 '22 03:10

mar10