2010-08-13 2 views
13

jstree에 노드를 동적으로 추가하는 코드를 작성하려고합니다. 나는 http://www.jstree.com/documentation/crrm에있는 문서를 따라 왔지만 간단한 예제가 작동하지 않는다. 노드 child2가 추가되고 있지만 지정된대로 'child1.id'가 아닌 'root.id'노드에 추가되고있다. .. 모든 팁을 많이 주시면 감사하겠습니다.프로그래밍 방식으로 자식 노드를 jstree에 추가하기

$("#tree").jstree("create", $("#child1\\.id"), "inside", { "data" : "child2" }, 
          function() { alert("added"); }, true); 

이 때문에 jQuery를 선택기를 사용하는 방법이다 : 당신은 너무처럼 탈출해야하는 ID의에서 기간을 사용하는 경우 코드

<html> 
<head> 
<script type="text/javascript" src="http://static.jstree.com/v.1.0rc2/jquery.js"></script> 
<script type="text/javascript" src="http://static.jstree.com/v.1.0rc2/jquery.jstree.js"></script> 

<script type="text/javascript"> 
$(document).ready(function() { 
    $(function() { 
     $("#tree").jstree({ 
      "json_data" : { 
       "data" : [ 
        { 
         "data" : "parent", 
         "attr" : { "id" : "root.id" }, 
         "children" : [ { "data" : "child1", 
             "attr" : { "id" : "child1.id" }, 
             "children" : [ ] } 
            ] 
        }, 
       ] 
      }, 
      "plugins" : [ "themes", "json_data", "crrm" ] 
     }); 
    }); 
    $("#add").click(function() { 
     $("#tree").jstree("create", $("#child1.id"), "inside", { "data" : "child2" }, 
          function() { alert("added"); }, true); 
    }); 
}); 
</script> 
</head> 

<body> 

<div id="tree" name="tree"></div> 

<input type="button" id="add" value="add" /> 
</body> 
</html> 
+0

나를 위해, "create"작업이 작동하지 않았습니다 ... 나는 sp ecified "create_node"그리고 그것은 효과가있다! –

+0

가치가있는 것을 위해, 나는 일하기 위해'창조 '를 얻을 수 없었다. 'create_node'가 효과가 있었지만 매개 변수가 달라야한다고 생각합니다. 그들의 문서가 그렇게 쓸모 없다면 좋을 것입니다. 'create_node' 메소드에 대한 문서를 어디서 찾을 수 있는지 알고 있습니까? – Brad

+0

http://www.jstree.com/documentation 핵심 문서 하이퍼 링크로 이동 – Ashwin

답변

3

첫 번째 (내 경우에는 내가 아약스를 사용), 핵심 OBJ에 check_callback 넣어 jstree를 초기화하고이 같은 핵심 OBJ 후 플러그인을 호출

jQuery('#jstree_demo_div').jstree({ 
    'core' : { 
      'data' : { 
      'url' : 'data/mapas.php', 

      }, 
      "check_callback" : function(e,data){ 
       console.log(data) 
      } 
     }, 
     "plugins" : [ "contextmenu" ] }) 

두 번째 줄을 사용하여 $ ('# j1_1')을 부모로두고, json의 데이터를 'last'로 위치 또는 'first'로 지정하고, 함수 콜백 (내 경우 tales() 함수), 내부 인수 설정 true