2012-02-15 2 views
0

Я заполняю представление JSTree с помощью команд ajax. Мой текущий код JS выглядит следующим образомЗаполнение URL-адреса AJAX в JSTree с информацией о модели

$(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"] 
     }); 
    }); 

Я хотел бы устранить, если заявление от собственности «Аякса» и заполнить его с данными JSON, которое приходит с сервера. Данные JSON выглядит так

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

Как я могу кормить свойство «Аякса» из JSON в собственность «Аякса» в JSTree?

ответ

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() { 
        } 
       } 
      }, 
Смежные вопросы