0

I want to represent a tree-structure using Jstree. I am facing the problem that the server does not returns the data in a jstree-compliant format - it's just ordinary Json.

One solution that I implemented is to use the json_data.ajax.success callback to modify the data in order to bring it to the required format. However, this function does not get context information - therefore, I don't know what node is being loaded and don't know how I have to transform the received data.

I have seen that there is a types plugin that allows different behaviour between nodes - for example, displaying a corresponding icon. Is it possible to use this plugin to add different ajax-success-handlers for each node type? If not, what other solutions are there?

$("#tree").jstree({
    "plugins": ["json_data", "themes", "types"],
    "json_data": {
        "ajax": {
            "url": function (n) {   // want to make this type-dependent.
                if (n === -1) {
                    return "...";
                } else if ( ... ) {
                    return "...";
                }
            },
            "success": function (data) {    // want to make this type-dependent
                var result = [];
                $.each(data, function (index, value) {
                    "data": "......",
                    "attr": {
                        "id": ".................",
                        "rel":  "..............."
                    }
                });
                return result;
            }
        }
    }
}
4

1 回答 1

1

You can create json data for jsTree on a server site and then process it one more time on the server to add whatever attributes for jsTree and then you can use types plugin.

于 2012-10-24T21:18:38.507 回答