2012-02-15 2 views
0

나는 ajax 명령으로 JSTree 뷰를 생성하고있다. 나는 "아약스"속성에서 if 문을 제거하고 서버에서 오는 JSON 데이터로 채우기 싶습니다JSTree에서 AJAX url을 모델 정보로 채우기

$(document).ready(function() { 
     $("#navigation").jstree({ 
      "json_data": { 
       "ajax": { 
        "url": function (node) { 
         var nodeId = ""; 
         var url = ""; 
         if (node == -1) { 
          url = "@Url.Action("BaseTreeItems", "Events")"; 
         } else { 
          nodeId = node.attr('id'); 
          url = "@Url.Action("EventTreeItems", "Events")" +"?selectedYear=" + nodeId; 
         } 
         return url; 
        }, 
        "dataType": "text json", 
        "contentType": "application/json charset=utf-8", 
        "data": function(n) { return { id: n.attr ? n.attr("id") : 0 }; }, 
        "success": function() { 
        } 
       } 
      }, 
      "themes": { 
       "theme": "classic" 
      }, 
      "plugins": ["themes", "json_data", "ui"] 
     }); 
    }); 

를 다음과 같이 내 현재 JS 코드입니다. JSON 데이터 내가 JSTree에서 "아약스"속성으로 JSON에서 "아약스"속성을 먹일 수있는 방법이

[{"data":{"title":"2012","attr":{"href":"/Events/EventList?selectedYear=2012"}},"attr":{"id":"2012","selected":false,"ajax":"/Events/EventTreeItems?selectedYear=2012"},"children":null,"state":"closed"},.....] 

처럼 보인다? 나중에 참조 할 수 있도록

답변

1

나는 다음

.jstree({ 
      "json_data": { 
       "ajax": { 
        "url": function (node) { 
         var url; 
         if (node == -1) { 
          url = "@Url.Action("BaseTreeItems", "Events")"; 
         } else { 
          url = node.attr('ajax'); 
         } 
         return url; 
        }, 
        "dataType": "text json", 
        "contentType": "application/json charset=utf-8", 
        "data": function(n) { return { id: n.attr ? n.attr("id") : 0, ajax: n.attr ? n.attr("ajax") : 0 }; }, 
        "success": function() { 
        } 
       } 
      }, 
를 수행하여 고정
관련 문제