I have this structure in json I can not be modified by request.
{
"Object": [
{
"url": "http://www.google.com"
}
],
"id": 1,
"name": "Redirection Rule",
"Object": {
"frequency": 1,
"trigger": 1
},
"Object": {
"http": "Redirect Url",
"response": 301
}
}
I need to use this structure to populate a jstree . I just need to use the "id" fields and "name", how do I set jstree to use "name" instead of "text" as a node name ?
jsTree is jquery plugin, that provides interactive trees. It is absolutely free, open source and distributed under the MIT license. jsTree is easily extendable, themable and configurable, it supports HTML & JSON data sources and AJAX loading.
jsTree needs a specific format to work with JSON. In the standard syntax no fields are required - pass only what you need. Keep in mind you will be able to access any additional properties you specify - jsTree won't touch them and you will be able to use them later on (using the original property on each node).
This plugin adds additional information about selection changes. Once included in the plugins config option, each changed.jstree event data will contain a new property named changed, which will give information about selected and deselected nodes since the last changed.jstree event
Just use a standard jQuery-like AJAX config and jstree will automatically make an AJAX request populate the tree with the response. Add a class of jstree-closed to any LI node you return and do not nest an UL node and jstree will make another AJAX call as soon as the user opens this node.
Either:
1) use the jQuery dataFilter
option (this means defining a function for dataFilter
in your core.data
jsTree config),
or
2) set core.data
itself to a function, manually make the request and transform it like so:
$('#your-tree').jstree({
core : {
data : function (node, cb) {
$.ajax({ url : ... }).done(function (data) {
cb([{ "id" : data.id, "text" : data.name }])
});
}, ...
You can find more info on setting core.data
to a function here:
https://github.com/vakata/jstree#populating-the-tree-using-a-callback-function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With