2016-04-08 7 views
1

Ich habe unter Code zum Laden jstree. Aber jstree wird nie geladen.JStree nicht laden

$("#div").jstree({  
     'json_data': {  
      'ajax': {  
       'url': ajaxUrl,  
        'type': 'GET',  
        'data': function(data) {  
        }, 
      } 
     } 
    }); 

Was mache ich hier falsch?

Antwort

0

Sie haben nicht den vollständigen Code oder wie Ihre Quelle JSON-Daten aussieht. Aber hier ist ein Beispiel für das Laden von Jstree mit Ajax-Inhalten.

$(function() { 
$.ajaxSetup({cache:false}); 
$("#jsonDemo").jstree({   
    "plugins" : [ 
     "themes","json_data", "ui" 
    ], 

    // This example uses JSON as it is most common 
    "json_data" : { 
     "data" : [{"attr":{"id":"1204","isLast":"false","name":"A Node"}, 
         "data":"A Node", 
        "metadata":{"id":"1204","isLast":"false","name":"A Node"}, 
         "state":"closed"}, 
        {"attr":{"id":"1205","isLast":"true","name":"B Node"}, 
        "data":"B Node", 
        "metadata":{"id":"1205","isLast":"true","name":"B Node"}, 
        "state":"close"} 
       ], 
     "ajax" : { "url" : "./_demo/_tree_json.json", 
         "data": function (n){ 
          return{ 
           //set the url request param,multi param separate by , 
            "parentId" : n.attr ? n.attr("id") : "null", 
            "name": n.attr ? n.attr("name") : "null" 
          }; 
        } 
     } 
    }, 
    "themes" : { 
     "theme" : "classic", //apple,default,if in ie6 recommented you use classic 
     "dots" : true, 
     "icons" : true 
    } 

}) 
.bind("select_node.jstree",function(event,data){ 
     if("true" == data.rslt.obj.attr("isLast")){ 
      //get the attrs data you set in the attrs field; 
      alert(data.rslt.obj.attr("id")+data.rslt.obj.attr("isLast")); 
      //you can do something here... 
     }else{ 
      //toggle node refer to the id setted in the metadata 
      //get the metadata id field value : jQuery.data(data.rslt.obj[0], "id"); 
      //The metadata id value should be different to each other !!! 
      //otherwise, the toggle_node will work incorrect !!! 
      $("#jsonDemo").jstree("toggle_node","#"+jQuery.data(data.rslt.obj[0], "id")); 
     }  
}) 
// prevent the default event of the link 
.delegate("a", "click", function (event, data) { event.preventDefault(); }) 
; 
});