How to change ajax response before creating jsTree?

How can I change the ajax response before creating jsTree? I would like to access each node identifier and add a prefix to it. The only hint on the jsTree page is this: the function will receive two arguments - the load node and the function. "I need to do this before the tree is actually created to avoid duplicate identifiers in the document.

"json_data" : { "ajax" : { "type": "GET", "url" : "tree.json" }, "data" : function(node, func){ //how to use that? }} 

I expected to get JSON data here, change it and come back? But it will explode.

+4
source share
1 answer

I have successfully manipulated data using the success callback in creating jsTree. In my case, I parse the XML data returned as JSON from the .NET web method. This should work for your business in a similar way.

 "ajax": { "type": "GET" "url": "tree.json", "success": function (x) { //manipulate string x to change id here return x; }, ... 

Another method is to use the "full" callback function to control jsTree in its final form. However, I do not recommend it in case of duplicate identifier.

+4
source

Source: https://habr.com/ru/post/1369626/


All Articles