mbraak / jqTree

Tree widget for jQuery
https://mbraak.github.io/jqTree/
Apache License 2.0
1.02k stars 177 forks source link

Change data-url based on the node type when using load_on_demand #114

Closed jqlearner closed 11 years ago

jqlearner commented 11 years ago

Thanks for providing this widget. This works great with async data load on demand. However, I would like to know if there is a way to modify the data-url based on the node type before calling the server to load the node.

I have this div:

<div id="sample-tree" data-url="http://localhost/SampleApp/GetChildren/"

I would like to pass the node type in the data-url as query string along with the node id based on my current node.

Also, is there any event that triggers before the tree loads the node (where I can change the data-url)?

mbraak commented 11 years ago

The dataUrl option has some undocumented features (that will soon be documented).

The dataUrl option can be a function:

$tree.tree({
    dataUrl: function(node) {
        var url = '/my_url/';

        if (node) {
            // Load data on demand for this node
            url += node.id;
        }

        return url;
    }
});

The function can also return an object. JqTree will make an url from this object:

function(node) {
    var result = {
        'url': '/my_url/'
    };

    if (node) {
        result['data'] = {
            'node': node.id
        };
    }

    return result;
}

Also see issue 80.

jqlearner commented 11 years ago

Thanks much. That worked!