JStree和ajax

我正在尝试使用ajax数据更新我的js树。 我想在从ajax.Kindly帮助中获取所有数据后才更新树。 但我得到的错误是“Uncaught TypeError:$(…)。jstree(…)不是HTMLDocument.eval的函数(eval at(jquery.min.js:2)”我的代码如下: –

   #tree { margin-top: 50px; }    <script src='https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/jstree.min.js'         Click a node 
var data =[] var data = [ { "id" : "root", "parent" : "#", "text" : "Root", "state": {"opened":false} }, ] var my_dictionary = {}; var flag = false; $(document).ready(function() { var my_dictionary = {}; //var DatesNew = Date1+"|"+Date2; //my_dictionary['Dates'] = DatesNew; console.log("in len of data is...",data.length); console.log("lennnnnnnnnnnnnnnnnof data is...",data.length); $.ajax({ url: '/ajax5/', data1:my_dictionary, cache: false, success: function (data1) { //myFunction1(); console.log("in before LOOP AJAX5...",data1); printData1(data1); } }).done(function(data1){ console.log("done with ajax call"); flag = true; }); }); function printData1(data1) { console.log("in before printData1 is...",data1); var lab =["1","2","3"]; var val = [42,55,51,22]; //var data = []; for(var i=0; i '; console.log("The selected nodes are:"); console.log(data.selected); var path = data.instance.get_path(data.node,'.'); console.log('Selected: ' + path); //alert( $('#tree').jstree().get_path(data.node, glue, true ) ); }) }); });

为了确保在获得ajax响应后开始构建树,我将按以下方式执行:

 $(document).ready(function() { var my_dictionary = {}; $.ajax({ url: '/ajax5/', data1: my_dictionary, cache: false, success: function(data1) { _buildTree(); // call function that builds the tree } }).done(function(data1) { console.log("done with ajax call"); }); // function that builds the tree function _buildTree() { $('#tree') .jstree({ 'plugins': ["checkbox"] }) .on('select_node.jstree', function(event, data) { var glue = ' > '; var path = data.instance.get_path(data.node, '.'); console.log('Selected: ' + path); }) } });